[GNC-dev] Python code formatter - black

John Ralls jralls at ceridwen.us
Sat Jul 11 12:00:36 EDT 2020


Not much of a comparison. I thought it interesting that the author complained of black reducing vertical space and I complained of it increasing it. I suppose it has a toggle: If a statement will fit on a line put it on a line otherwise add parentheses and break on every comma.

https://books.agiliq.com/projects/essential-python-tools/en/latest/linters.html covers more tools and has a bit more to say about each.

This https://luminousmen.com/post/my-unpopular-opinion-about-black-code-formatter has some good points about formatting in general and where Black has (in his opinion) gone wrong. I agree with him, and with GVR: The objective is to write expressive, easily understood code because it makes the code more maintainable later on. Black apparently has a different goal, to make code that diffs uniformly. 

Regards,
John Ralls

> On Jul 11, 2020, at 6:06 AM, c.holtermann at gmx.de wrote:
> 
> Ok, I'll have a look at different ones. Try them on my commits and on
> the way maybe we'll agree on one (with certain settings) for the whole
> python codebase. Black is basically not configurable. Here's one article
> comparing black, yapf, autopep8 but not pylint:
> https://blog.frank-mich.com/python-code-formatters-comparison-black-autopep8-and-yapf/
> 
> regards,
> 
> Christoph Holtermann
> 
> 
> Am 2020-07-07 19:06, schrieb John Ralls:
>> PyLint is the granddaddy and semi-official python formatter and
>> linter. Lots of Python projects require a PyLint check with a minimum
>> score to merge commits.
>> 
>> Regards,
>> John Ralls
>> 
>> 
>>> On Jul 7, 2020, at 9:23 AM, c.holtermann at gmx.de wrote:
>>> 
>>> I looked around and liked black but I haven't compared it to PyLint.
>>> Do
>>> you like that one better?
>>> 
>>> Regards,
>>> 
>>> Christoph Holtermann
>>> 
>>> Am 2020-07-07 17:06, schrieb John Ralls:
>>>> Is there a reason you don't want to use PyLint?
>>>> 
>>>> Regards,
>>>> John Ralls
>>>> 
>>>>> On Jul 6, 2020, at 10:22 PM, c.holtermann at gmx.de wrote:
>>>>> 
>>>>> I have used it as is without config. I'll have a look which options
>>>>> there
>>>>> are for configuration and if what you have in mind is configurable.
>>>>> 
>>>>> regards,
>>>>> 
>>>>> Christoph Holtermann
>>>>> 
>>>>> 
>>>>> Am 2020-07-07 05:21, schrieb John Ralls:
>>>>>> It's mostly OK, but some of the vertical space changes are
>>>>>> excessive
>>>>>> in particular gncinvoice_jinja.py line 213 and latex_invoices.py
>>>>>> line
>>>>>> 65.
>>>>>> 
>>>>>> I don't much care for the way it handled gncinvoice_jinja.py line
>>>>>> 207
>>>>>> either: I'd prefer to move the comment above the line and if it's
>>>>>> still too wide drop the whole call, like so:
>>>>>>   # something like 2004-11-01
>>>>>>   filename_date =
>>>>>>       invoice.GetDatePosted().strftime("%Y-%m-%d")
>>>>>> 
>>>>>> But that's probably too much to ask of an automated tool.
>>>>>> 
>>>>>> Regards,
>>>>>> John Ralls
>>>>>> 
>>>>>>> On Jul 6, 2020, at 1:10 PM, c.holtermann at gmx.de wrote:
>>>>>>> 
>>>>>>> Hello folks,
>>>>>>> 
>>>>>>> I'd like to use a code formatter on the python bindings. I tried
>>>>>>> black
>>>>>>> [1] and liked what I saw. Would you be ok with reformatting the
>>>>>>> whole
>>>>>>> python bindings with it?
>>>>>>> I used it on two example scripts:
>>>>>>> https://github.com/Gnucash/gnucash/pull/736/commits/0434acbe1035ed679d23242a412c48a680ac5a07
>>>>>>> 
>>>>>>> 
>>>>>>> regards,
>>>>>>> 
>>>>>>> Christoph Holtermann
>>>>>>> 
>>>>>>> Links:
>>>>>>> ------
>>>>>>> [1] https://github.com/psf/black
>>>>>>> _______________________________________________
>>>>>>> gnucash-devel mailing list
>>>>>>> gnucash-devel at gnucash.org
>>>>>>> https://lists.gnucash.org/mailman/listinfo/gnucash-devel



More information about the gnucash-devel mailing list