pywin32 icon indicating copy to clipboard operation
pywin32 copied to clipboard

pylint, mypy and Pyright don't know about some module symbols

Open Avasam opened this issue 3 years ago • 3 comments

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.error to 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: image

  • Version of Python and pywin32 304

Edit: Same with Pythonwin's win32ui.error

Avasam avatar Jul 14 '22 22:07 Avasam

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.

mhammond avatar Jul 14 '22 23:07 mhammond

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.

Avasam avatar Sep 29 '22 19:09 Avasam

As I've already said, I've no interest in doing any work to support this, but would look at a PR.

mhammond avatar Oct 01 '22 00:10 mhammond

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.

Avasam avatar Nov 30 '22 22:11 Avasam

The next pywin32 build will have 3.7 as the min supported version.

mhammond avatar Dec 01 '22 00:12 mhammond

Oh awesome! Minimum version supported by mypy too. I guess I'll get started then.

Avasam avatar Dec 01 '22 00:12 Avasam

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).

Avasam avatar May 08 '23 15:05 Avasam