Closed dimaqq closed 2 weeks ago
Your code is relying on side effects of the import loader that pyright does not model. This is by design, so I don't consider this a bug.
You'll need to change your code if you want it to work with pyright.
Thank you for quick response.
Maybe I can get some advice how to best achieve what I'm really trying to do:
In the past we have ops/main.py: def main(..): ...
:
from ops.main import main; main(...)
import ops.main; ops.main.main(...)
We can't afford a breaking change, but we want:
import ops; ops.main(...)
In our case, the new way of calling main was introduced before the package got typed.
P.S. there seem to some kind of spam going around on GitHub, this issue got a comment from spammer, right above. We're reporting and deleting these comments in our repos, but it seems that only maintainers can do so.
Given following
ops/__init__.py
:And this the test code below, pyright doesn't agree with Python run time:
In fact, all 3 imports+call styles work OK at run time.
Full MRE: https://github.com/dimaqq/MRE-pyright-submodule-import Tested:
pyright 1.1.377
Note that if
from . import main as _main
is removed, pyright's interpretation of submodule import becomes correct, but then pyright doesn't catch the function import.