我想在我的项目中引入部分类型注释。例如重载。我发现 pep561 引入了部分存根文件支持。
我使用 PyCharm 开发我的项目并添加相应的*.pyi
文件。并得到了预期的信息,但 PyCharm 报告在 pyi 文件中找不到参考。
当 pyi 文件中没有条目时,是否可以强制 PyCharm 查看原始 py 文件?或者也许它也可以部分进入课堂?
├── main.py
└── pep561_test
├── __init__.py
└── __init__.pyi
主文件
from pep561_test import AA, BB, CC
AA().test1(1)
AA().test1(True)
AA().test1('a')
AA().test2(1)
BB().test1(1)
BB().test2(1)
__init__.py
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
__init__.pyi
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