Replies: 2 comments 4 replies
-
|
Stub files are always preferred over normal source files when resolving imports. This behavior is described by PEP 561 and mandated by the Python typing spec, and pyright is compliant with the spec. It sounds like what you're asking for is to somehow "merge" the type information in a stub file with the type information in a corresponding source file, using the former to type check the latter? That's not what stub files were designed for. In general, that wouldn't be possible given the design of stubs. It's unlikely that pyright (or any other standards-compliant type checker) would support this feature. A stub is meant as a "stand-in" for a source file. It's not meant to somehow "augment" the type information in a source file. |
Beta Was this translation helpful? Give feedback.
-
|
So solution is I can't use pyright for this? Can't pyright be ahead of PEP standards? Enabled by some config flag? Is my use case too rare?
PyCharm does internally support pyi files next to the py files without complaints. The pyi syntax is spot on. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I understand the purpose of pyi files:
But there's a third category which is not supported by pyright.
So now my own local project has "invisible code" which is resulting in missing type hints. I'm speaking of PySide/PyQt user interfaces which can also be loaded during runtime right from ".ui" files.
Here's a description of my tool that creates pyi stubs including reasons for this method: https://github.com/sausix/qtui2pyi
Having pyi files along py modules works fine in PyCharm. But I could not get pyi files be preferred in pyright. It does not work by having
main.pyandmain.pyiin the same directory. Also doesn't work by having{"include": ["src"], "stubPath": "typings"}.Can we have an option in pyright which loads pyi files prior to the corresponding py files?
Example usage with current warning:
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions