I would like to introduce partial type annotation to my project. For example for overloading. I found that pep561 introduce partial stub file support.
I develop my project with PyCharm and I add corresponding *.pyi
file. And got expected information, but PyCharm reports that cannot find reference in pyi file.
It is possible to force PyCharm to look to orginal py file when there is no entry in pyi file? Or maybe it is also doable with partial entry for class?
I create sample project to show problem (orginal is to big):
├── main.py
└── pep561_test
├── __init__.py
└── __init__.pyi
main.py
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
py
andpyi
stub for the same file, from the PEP 561: "This can be thought of as the functional equivalent of copying the stub package into the same directory as the corresponding runtime package ... and type checking the combined directory structure". This way__init__.pyi
will override__init__.py
.mypy
can't do it as well as PyCharm:main.py:1: error: Module 'pep561_test' has no attribute 'CC'
– Furlongpy
file? – Caseworm# noinspection PyOverloads
when adding type annotations for autogenerated methods.. – Essayist