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 hints to comtypes/__init__.py #364

Merged
merged 2 commits into from
Nov 2, 2022

Conversation

junkmd
Copy link
Collaborator

@junkmd junkmd commented Nov 2, 2022

related to #327

This PR introduces type hints into statically defined modules.

  • Scattered imports are now grouped together at the beginning of the code.
    • As for add_metaclass, it was moved where "if it was imported from six, it would be about here."
  • Annotation-only symbols are imported from typing using TYPE_CHECKING, so List, Tuple and others are not in the runtime namespace.
  • In the case of _IUnknown_Base, whose definition exists in runtime, is prevented from being used in gen by add __known_symbols__ attributes to each modules for preventing unexpected symbols are imported to comtypes.gen._xxx... #360.
  • For field annotations, defining AnnoField in hints.pyi. This can be used only under if TYPE_CHECKING.

In order to add more type annotations in the future, there are more symbols imported from typing than I use this time.

  • I think it is better than having changes in the import part over and over.

junkmd added a commit to junkmd/pywinauto that referenced this pull request Nov 2, 2022
vasily-v-ryabov added a commit to vasily-v-ryabov/pywinauto that referenced this pull request Nov 2, 2022
@vasily-v-ryabov vasily-v-ryabov merged commit b331d3c into enthought:master Nov 2, 2022
@junkmd junkmd deleted the first_type_hints branch November 2, 2022 20:09
@kdschlosser
Copy link
Contributor

I know this is merged but there is a problem with how the type annotations are being done.

Why are Python 2 style annotations being used? For starters these are not going to stay and are going to get removed from Python. The second thing is they are not compatible with inspect.signature and no annotations will be available.

The 3rd thing is the use of pyi files is really for c extensions where type hints cannot be read. If it's a python source file then all the type hints should be located in that source file.

@vasily-v-ryabov
Copy link
Collaborator

@kdschlosser this was my suggestion to keep Py2.7 compatibility for some more time. The current plan is to drop Py2.7 support in the middle of 2023 or maybe even earlier (after some release).

@kdschlosser
Copy link
Contributor

It's a lot of work that is going to end up having to be redone in a year or potentially less for type hinting which hasn't been used for how many years now? I think the library will be able to get along for <= 1 year without type hints so they can be done a single time and done properly for Python 3. It is a lot of time spent to end up having it all undone in the not too distant future,

Just my thoughts on it.

@junkmd
Copy link
Collaborator Author

junkmd commented Dec 4, 2022

In addition to what I planned in #327, I have added typehints in this format to typeinfo, codegenerator and typedesc, but I do not plan to write any more typehints in this format for modules other than these except for modifications.

As for comment annotations, I believe that it is not difficult to convert them to inline annotations since there are tools such as https://github.com/ilevkivskyi/com2ann.

The Structure and Union fields need to be considered and are being discussed in #327.

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 this pull request may close these issues.

None yet

3 participants