是的,我理解black
在让它采取不同的行动方面几乎没有余地,但我想知道处理这种事情的最佳方式(我的原始代码):
@dataclass
class Thing1:
property1: int # The first property.
property2: typing.List[int] # This is the second property
# and the comment crosses multiple lines.
现在,当我将其运行到black
时,它会给我:
@dataclass
class Thing1:
property1: int # The first property.
property2: typing.List[int] # This is the second property
# and the comment crosses multiple lines.
这并不是我想要的.
有没有办法让黑人保持 comments 的一致性?我不在乎它从每个字段的哪个列开始,但最好返回可读性,将each个字段内的注释排列起来:
@dataclass
class Thing1:
property1: int # The first property.
property2: typing.List[int] # This is the second property
# and the comment crosses multiple lines.
如果无法做到这一点,我可能会在每个字段之前放置多行注释,或者确保所有注释都适合一行,并在数据类定义的末尾添加更长的解释性注释:
@dataclass
class Thing1:
property1: int # The first property.
# This is the second property and the comment, while it can
# have more characters, still crosses multiple lines.
property2: typing.List[int]
@dataclass
class Thing2:
property1: int # The first property.
property2: typing.List[int] # This is the second property.
# Note that the comments above now fit on the same line as the
# field, and this comment here is meant to provide any needed
# multi-line detail for ALL fields in this class.
对于数据字段来说,这至少仍然是somewhat个局部变量.但如果可能的话,我宁愿找到一种方法,让它把 comments 排成与我最初的 comments 类似的行.
很乐意接受任何建议.