Skip to content

Conversation

@Avasam
Copy link
Collaborator

@AvasamAvasam commented Oct 2, 2022

Helps with microsoft/python-type-stubs#211

This PR does not intend to complete the types for pywin32. Due to the size of this stub, it will be done in multiple steps:

  1. (this) Make the stubs at least as good as https://github.com/microsoft/python-type-stubs and https://github.com/mhammond/pywin32 combined.
    • Add everything from both stubs
    • Upon duplicates, use the most complete version of any function, method, class, type, etc.
    • Remove all explicit Any types (or use Incomplete when that was not possible)
    • Incomplete methods from https://github.com/microsoft/python-type-stubs have been updated with (*args, **kwargs): ... # incomplete
    • Incomplete modules detected by stubtest (on Windows) have def __getattr__(self, __name: str) -> Any: ... # incomplete added to them
    • Complete any type needed for strict pyright checking in https://github.com/Avasam/Auto-Split
    • Fixed the basetype for error classes
    • Fix anything found by typeshed's tooling
  2. (future PR) Complete existing modules and add all missing (non-private) modules with the help of stubgen
  3. Let the community work on completing stubs to eventually turn on pyright strict typing.

from microsoft/python-type-stubs and mhammond/pywin32
@github-actions

This comment has been minimized.

@Avasam
Copy link
CollaboratorAuthor

Avasam commented Oct 3, 2022

About that primer error:
pythoncom.py is a module that lives directly in sites-package, I tried with both stubs/pywin32/pythoncom.pyi and stubs/pywin32/pythoncom/__init__.pyi in typeshed without success, not sure how to fix that.

@AlexWaygood
Copy link
Member

About that primer error:
pythoncom.py is a module that lives directly in sites-package, I tried with both pythoncom.pyi and pythoncom/__init__.pyi in typeshed without success, not sure how to fix that.

The primer output is good! It shows that mypy currently emits an error when checking comtypes due to the lack of types for pywin32. But this PR would (if they started using these stubs) fix that error!

@Avasam
Copy link
CollaboratorAuthor

Avasam commented Oct 3, 2022

Oh I get it now, it's a diff saying those errors would not be in the output anymore! I'll revert back to a single module since that's more accurate.

Copy link
Member

@JelleZijlstraJelleZijlstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is great! I have a few comments but I can't review this in detail, both because of its size and because I don't have access to Windows :)

I say we merge it (after giving other maintainers a chance to have their say) and handle any further improvements in separate PRs.

from typing_extensions import final

class PyDSCAPSType:
def __new__(cls): ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of these __new__ methods in the stubs? Wouldn't the stub behave the same without them?

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure there's not point and they're just leftovers from copying the original stubs

@@ -0,0 +1,66 @@
APPBREAKFLAG_DEBUGGER_BLOCK = ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these all ints? Can we use : int for them?

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

comtypes (https://github.com/enthought/comtypes) - comtypes/test/test_win32com_interop.py:13: error: Cannot find implementation or library stub for module named "pythoncom"- comtypes/test/test_safearray.py:239: error: Cannot find implementation or library stub for module named "pythoncom"

@JelleZijlstraJelleZijlstra merged commit 0b71c96 into python:masterOct 3, 2022
@AvasamAvasam deleted the pywin32-existing-stubs branch October 3, 2022 16:35
hauntsaninja pushed a commit to python/mypy that referenced this pull request Dec 20, 2022
Removals from `stubinfo.py`: - `atomicwrites` is archived and deprecated at runtime; stubs were removed from typeshed in python/typeshed#8925 - `attrs` has had inline types for a very long time now - `chardet` recently cut a release with inline types; typeshed's stubs were marked obsolete in python/typeshed#9318 - `cryptography` has had inline types for a very long time now; the only reason why it's still in typeshed is because other typeshed packages need `types-cryptography` as a dependency, and our testing infrastructure therefore can't currently cope with it being removed from typeshed. - `emoji` recently cut a release bundling stubs with the runtime package; typeshed's stubs were marked obsolete in python/typeshed#9051 - `termcolor` recently cut a release with inline types; typeshed's stubs were marked obsolete in python/typeshed#8746 - `prettytable` recently cut a release with inline types; typeshed's stubs were marked obsolete in python/typeshed#9023 Additions: - Stubs for `Xlib` were added in python/typeshed#9279 - Stubs for `consolemenu` were added in python/typeshed#8820 - Stubs for `dockerfile_parse` were added in python/typeshed#9305 - Stubs for `flask_migrate` were added in python/typeshed#8967 - Stubs for `paho.mqtt` were added in python/typeshed#8853 - Stubs for `pycocotools` were added in python/typeshed#9086 - Stubs for many `pywin32` modules were added in python/typeshed#8825, and multiple follow-up PRs - Stubs for `pyscreeze` were added in python/typeshed#8823
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@Avasam@AlexWaygood@JelleZijlstra