简体   繁体   English

类实现中的python stub属性“未解析的属性参考”

[英]python stub property “Unresolved Attribute Reference” in Class Implementation

I made a Class Interface in my pyi module (scheme.pyi): 我在pyi模块(scheme.pyi)中创建了一个类接口:

class Catalog:

    @property
    def elements(self) -> List[Element]: ...

and in my scheme.py I implemented the class like this: 在我的scheme.py中,我实现了这样的类:

class Catalog:

    def __init__(self, element_collection):
        self.__elements = element_collection

    @property
    def elements(self):
        return self.__elements

PyCharm says "Unresolved Attribute Reference "__elements" for class Catalog" PyCharm说“类目录的未解决属性参考“ __elements””

I think it will work if you make Class Interface like so: 我认为如果您像这样制作Class Interface,它将起作用:

class Catalog:

    def __init__(self, element_collection) -> None:
        self.__elements: List[Element]

    @property
    def elements(self) -> List[Element]:

or you can optionally declare instance variables in the class body like so: 或者,您可以选择在类主体中声明实例变量,如下所示:

class Catalog:

    self.__elements: List[Element]

    @property
    def elements(self) -> List[Element]:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM