gpt4 book ai didi

python - 文档字符串中 PyCharm 中 Unresolved 属性引用问题

转载 作者:行者123 更新时间:2023-12-05 05:06:46 26 4
gpt4 key购买 nike

当我使用 attrs 库创建类时,PyCharm 中的 docstring 显示一个 linting 错误 unresolved attribute reference

另一方面,当我通常使用 __init__ 方法创建类时。它没有显示这样的错误。

我无法确定此错误是由 attrs 或 PyCharm 引起的,因为默认情况下 attrs 具有 mypy 类型检查所需的所有 stub 。在使用 attrs 时,除了这一次在 docstrings 中之外,到目前为止我找不到任何 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 错误如下图所示 --

enter image description here

如有任何帮助,我们将不胜感激。

最佳答案

这是 PyCharm 中的错误。 attrs 无法对他们的分析做任何事情,特别是考虑到检查文档字符串完全是他们的功能。据我所知,他们根本不在内部使用 mypy,必须自己重新实现所有内容。

附言如果你使用 @attr.s(auto_attrib=True)

,你可以只写 attribute_with_attr: str = "some_string_value"

关于python - 文档字符串中 PyCharm 中 Unresolved 属性引用问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59624799/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com