[Tutor] A Question about coding style

Cameron Simpson cs at cskk.id.au
Thu Sep 23 05:36:59 EDT 2021


On 23Sep2021 09:34, Albert-Jan Roskam <sjeik_appie at hotmail.com> wrote:
>     > This style is uncommon. On a personal
>
>     > basis I tend to use styles like this if I have several very short
>     test/action pairs. Example:
>
>         for x, y, z in some-3-tuples...:
>             if x < 0: x = 0
>             if y > 5: y = 6
>             if y + z > 10: z /= 2
>
>   ==>> I don't have Python here, but won't the "black" code prettifier
>   correct this? It's in my git hooks

"correct"? Reformat, sure. "correct" is in the eye of the beholder, and 
'black" is a very unforgiving beholder. I use yapf for my personal code, 
and it would might fold the lines above because it uses weights to make 
some of these decisions.

"black" enforces a very rigid interpretation of PEP8. "yapf" is more 
flexible, and has many knobs to adjust its behaviour - its defaults are 
basicly PEP8 and indeed you can define a style as "start with PEP8 but 
make these changes", which is how I've defined my personal style for 
"yapf".

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Tutor mailing list