【问题标题】:How to stop Black from removing new lines in function call args?如何阻止 Black 删除函数调用 args 中的新行?
【发布时间】:2021-05-14 00:05:40
【问题描述】:

我想记录一个外部函数:

strange_function(
    # Comments about what this argument does
    param_1=True,

    # Comments about what this argument does
    param_2=False,
)

Black 将其重新格式化为:

strange_function(
    # Comments about what this argument does
    param_1=True,
    # Comments about what this argument does
    param_2=False,
)

想要param_1param_2 之间的新行,因为这样 cmets 更具可读性。但是黑色消除了这一点。它如何阻止它这样做?

【问题讨论】:

  • 黑色背后的整个想法不是不妥协,不会让你决定格式化等吗?
  • 它有一些选项。
  • 在评论参数时,我宁愿推荐使用多行文档字符串而不是像那样嵌入它
  • 同意@tbjorch,这是非常难以理解的。对该函数感兴趣的读者可能对该函数的签名感兴趣。单独的签名和文件!有关函数及其论点的文档,请参阅Python Docstring Conventions

标签: python pep8 python-black


【解决方案1】:

你不能。

黑色非常无情,只给你一个旋钮:每行允许多少个字符。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-13
    • 2022-01-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多