pylint, mypy and Pyright don't know about some module symbols
Note that issues in this repository are only for bugs or feature requests in the pywin32.
If you need support or help using this package, please follow these instructions - support or help requests will be closed without comment.
For all bugs, please provide the following information.
-
Expected behavior and actual behavior.
pywintypes.errorto exists during type-checking Pyright:error: "error" is not a known member of module (reportGeneralTypeIssues)pylint:E1101: Module 'pywintypes' has no 'error' member (no-member)Of course it does exist at runtime (result of the print below):(<class 'Exception'>,) (<class 'Exception'>,) -
Steps to reproduce the problem.
except pywintypes.error:
-
Version of Python and pywin32 304
Edit: Same with Pythonwin's win32ui.error
I don't see this as a bug in pywin32. I'd be happy with a simple fix (eg, some way of telling these tools that their introspection doesn't work) but wouldn't accept something like those .pyi files in the attached PR.
If the modules or symbols are not present in .py files (and the package marked as py.typed), the only way to type them for type checkers is to use type stubs (.pyi).
Third parties like https://github.com/kaluluosi/pywin32-stubs and https://github.com/microsoft/python-type-stubs (used by Pylance) can also provide them. But the most "official" way to have 3rd party stubs would be to go through https://github.com/python/typeshed/ , as popular type checkers bundle their stubs (python-type-stubs also aims to not keep their stubs and either hand them off to the package owners or typeshed).
If you don't want stubs to be added directly as part of pywin32, they can be provided by 3rd party and this can be closed.
As I've already said, I've no interest in doing any work to support this, but would look at a PR.
Type stubs for c-extension modules can live in typeshed indefinitely. Typing support for at least pure python modules would be great.
Python 3.5 did not yet support type annotations, so I'd rather wait for at least 3.6 to be the minimal supported version before opening a PR. So it doesn't have to be done through type comments.
The next pywin32 build will have 3.7 as the min supported version.
Oh awesome! Minimum version supported by mypy too. I guess I'll get started then.
This specific issue of c-modules not found is fixed by the stubs existing in typeshed. https://github.com/python/typeshed/tree/main/stubs/pywin32
For anyone else landing here: pip install types-pywin32. Pure-python modules type hints are in the work (see my ongoing PRs).