PyCharm中的部分存根

2024-10-03 21:27:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在我的项目中引入部分类型注释。例如过载。我发现pep561引入了部分存根文件支持。在

我用PyCharm开发我的项目,并添加相应的*.pyi文件。得到了预期的信息,但是PyCharm报告在pyi文件中找不到引用。在

当pyi文件中没有条目时,是否可以强制PyCharm查找原始py文件?或者它也可以用类的部分条目来实现?在

我创建了一个示例项目来显示问题(源于大): cannot find reference 'CC' in '__init__.pyi'

├── main.py
└── pep561_test
    ├── __init__.py
    └── __init__.pyi

在主.py在

^{pr2}$

初始值

class AA:
    def test1(self, a):
        pass

    def test2(self, a):
        pass


class BB:
    def test1(self, a):
        pass

    def test2(self, a):
        pass


class CC:
    def test1(self, a):
        pass

    def test2(self, a):
        pass

你的初始化

class AA:
    def test1(self, a: int) -> int: ...

    def test1(self, a: bool) -> str: ...

    def test2(self, a):
        pass


class BB:
    def test1(self, a):
        pass

Tags: 文件项目pyselfinitdef条目pass