Partial stub in PyCharm

社会主义新天地 提交于 2020-01-04 14:21:17

问题


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

来源:https://stackoverflow.com/questions/55160797/partial-stub-in-pycharm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!