黑色代码格式化程序行长度忽略包含的注释

Alv*_*ona 6 python formatting coding-style

因此,似乎 Black 代码格式化程序默认line-length选项也考虑了该行中包含的注释

例如

if some_very_long_variable_name_out_there_for_example is True: # just a random comment
    pass
Run Code Online (Sandbox Code Playgroud)

将在

if (
    some_very_long_variable_name_out_there_for_example is True
    ):  # just a random comment
    pass
Run Code Online (Sandbox Code Playgroud)

,就黑标准而言,这绝对是正确的

然而,该行if some_very_long_variable_name_out_there_for_example is True:实际上少于 88 个符号,我不希望我的代码因为我添加了注释而在视觉上被破坏

是否有禁用此类行为的选项?

Lau*_*t S 0

它并没有真正回答你的问题,但我想你可以养成这样的习惯:

# just a random comment on the previous line
if some_very_long_variable_name_out_there_for_example is True:
    pass
Run Code Online (Sandbox Code Playgroud)