【发布时间】:2020-04-24 17:54:43
【问题描述】:
当我使用attrs 库创建类时,PyCharm 中的 docstring 显示 linting 错误未解决的属性引用。
另一方面,当我通常使用__init__ 方法创建类时。它没有显示这样的错误。
我无法弄清楚这个错误是由于attrs 或 PyCharm 而产生的,因为attrs 默认情况下具有所有必要的用于 mypy 类型检查的存根。在使用attrs 时,到目前为止,除了文档字符串中的这次之外,我找不到任何 linting 错误。
import attr
@attr.s
class UsingAttrs:
"""
class created using attrs shows linting error.
Attributes
----------
attribute_with_attr : str
"""
attribute_with_attr: str = attr.ib(default='some_string_value')
class NotUsingAttrs:
"""
class created normally does not show linting error.
Attributes
----------
attribute_without_attr : str
"""
attribute_without_attr: str
def __init__(self, param='some string value'):
self.attribute_without_attr = param
Linting 错误如下图所示 --
任何帮助将不胜感激。
【问题讨论】:
-
@user2235698,刚刚投了赞成票。我想知道它已经两年了,还没有修复!
标签: python pycharm python-attrs