我不知道这是在,但我很高兴看到它。专业上,我使用了 3.6(没有这个),并且使用多个长行上下文管理器和black,很难格式化:
如果你有这个:
with some_really_long_context_manager(), and_something_else_makes_the_line_too_long():
pass
你必须写这个很难看:
with some_really_long_context_manager(), \
and_something_else_makes_the_line_too_long():
pass
如果你的论点太长:
with some_context(and_long_arguments), and_another(now_the_line_is_too_long):
pass
您可以执行以下操作:
with some_context(and_long_arguments), and_another(
now_the_line_is_too_long
):
pass
但是,如果一个上下文管理器不接受参数,那就行不通了,而且看起来有点奇怪:
with some_context(and_long_arguments), one_without_arguments(
), and_another(now_the_line_is_too_long):
pass
为此,您必须重新排列:
with some_context(and_long_arguments), and_another(
now_the_line_is_too_long
), one_without_arguments():
pass
使用新语法,可以将其格式化为:
with (
some_context(and_long_arguments),
one_without_arguments(),
and_another(now_the_line_is_too_long),
):
pass
这也使差异更具可读性。