Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Type Hint for win32api.GetLastError #2468

Open
songyuc opened this issue Jan 20, 2025 · 3 comments · May be fixed by #2469
Open

Add Type Hint for win32api.GetLastError #2468

songyuc opened this issue Jan 20, 2025 · 3 comments · May be fixed by #2469

Comments

@songyuc
Copy link

songyuc commented Jan 20, 2025

Hello,
When using PyCharm for development, the method win32api.GetLastError does not have an associated type hint in the win32api.pyi file. This absence leads to the following warning in PyCharm:

Cannot find reference 'GetLastError' in 'win32api.pyi'

This makes it difficult to utilize autocomplete and type checking features effectively.

Suggested Solution

Add a type hint for the GetLastError method in the win32api.pyi file to enhance IDE support and improve the development experience. The type hint should specify that GetLastError returns an integer.

# win32api.pyi
def GetLastError() -> int: ...

Additional Information

  • pywin32 version: 308
  • Development Environment: PyCharm 2024.3.1.1

Benefits

  • Improved IDE support with accurate autocomplete and type checking.
  • Enhanced developer experience by reducing misleading warnings in the code editor.

Thank you for maintaining the pywin32 library and for considering this enhancement!

@mhammond
Copy link
Owner

There are no .pyi files in the repo.

@songyuc
Copy link
Author

songyuc commented Jan 20, 2025

Thank you for the response. I am a student new to type-hints and .pyi files. I'm interested in learning how to add type hint support. Would you be open to accepting a PR for adding type hints? If so, do you have any specific guidelines or preferences for how you'd like to see type hints implemented in the project?

@Avasam Avasam linked a pull request Jan 20, 2025 that will close this issue
@Avasam
Copy link
Collaborator

Avasam commented Jan 20, 2025

Hello @songyuc . Type stubs for pywin32 are handled as third-party stubs in https://github.com/python/typeshed/tree/main/stubs/pywin32 . Feel free to re-open your issue there.

I opened #2469 to hopefully help direct users of type annotations to the proper resources.

accepting a PR for adding type hints

That is an absolute massive undertaking that I've been working on over the past 2 years now. pywin32 has some inline type annotations, and basic (but not great) static type-checking coverage of its own usage.
Mark H. has previously mentioned not wanting to add a bunch of stub files to pywin32 #1913 (comment) . Understandably so as it's only extra maintenance for him to keep synchronized.

What's most likely to happen, and my current plan, is that most pure-python modules in pywin32 get annotated. And c-extensions stay delegated to typeshed (third party stubs can be marked as partial for that exact purpose). Maybe in the very long term a C-to-pyi generator could be used. (something like this using SWIG swig/swig#735, or a tool like stubgen)
Here you can find in-progress PRs: https://github.com/mhammond/pywin32/pulls?q=sort%3Aupdated-desc+is%3Apr+is%3Aopen+mypy+OR+pyright

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants