Но когда я пишу сценарий, использующий MyModule, скажем, MyScript. пы:
Код: Выделить всё
from MyModule import MyClass, MyOtherClass
if __name__ == "__main__":
a = MyClass(1, 2)
a = MyOtherClass(90)
Код: Выделить всё
MyScript.py:1: error: Module "MyModule " has no attribute "MyClass" [attr-defined]
MyScript.py:1: error: Module "MyModule " has no attribute "MyOtherClass" [attr-defined]
- pathtomodule/
MyModule/
py.typed: пусто - __init__.py: пусто
- MyModule.py: содержит определение классов
Я заметил, что если я добавлю в __init__.py следующую строку, она будет работать:
Код: Выделить всё
from .MyModule import MyClass, MyOtherClass
Подробнее здесь: https://stackoverflow.com/questions/790 ... e-checking
Мобильная версия