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

Avoid using keywords in TYPE_CHECKING blocks. #589

Merged
merged 2 commits into from
Jul 19, 2024

Conversation

junkmd
Copy link
Collaborator

@junkmd junkmd commented Jul 17, 2024

fixes #588

junkmd added 2 commits July 16, 2024 00:00
If a keyword is used as a member name, replace it with `pass` and a comment.
Code within `TYPE_CHECKING` blocks are not executed at runtime, so they will
not result in `NameError` or `AttributeError`.
However, if method names or argument names use Python reserved words, or if
the statements or expressions are incorrect in Python syntax, a `SyntaxError`
will be raised.

The newly added tests ensure that `typeannotator` avoids such situations:
- If there are method names that match Python reserved words,
  `typeannotator` replaces them with `pass` and comments.
- If there are argument names that match Python reserved words,
  `typeannotator` replaces them with `*args` or `**kwargs`.
- If there are methods that specify required arguments after optional
  arguments, `typeannotator` replaces them with `**kwargs`.

It was challenging to find a "real-world" COM library that covered all these
cases. Therefore, in these tests, using `typedesc`s as a test double to
simulate the results of parsing a COM type library.

It has been confirmed through the discussions in the following issue that
the changes made to the production code in commit 35f3336 prevent errors from
occurring in a real COM library.
enthought#588 (comment)
@junkmd junkmd added bug Something isn't working typing related to Python static typing system labels Jul 17, 2024
@junkmd junkmd added this to the 1.4.6 milestone Jul 17, 2024
@junkmd
Copy link
Collaborator Author

junkmd commented Jul 17, 2024

This is a patch to fix the regression reported by @asamitov and @forderud.

junkmd added a commit to junkmd/pywinauto that referenced this pull request Jul 17, 2024
@forderud
Copy link
Contributor

Thank you so much for your quick support @junkmd

@junkmd junkmd merged commit 3c3448e into enthought:main Jul 19, 2024
49 checks passed
@junkmd junkmd deleted the fix_issue_588 branch July 19, 2024 12:58
@forderud
Copy link
Contributor

@junkmd I see that this fix is scheduled for the upcoming 1.4.6 release. Any idea of when this release will be published?

@junkmd
Copy link
Collaborator Author

junkmd commented Jul 26, 2024

@forderud

I am planning to release comtypes==1.4.6 in the second week of August, probably on Monday morning (Japan time).
I am avoiding the third week of August because it coincides with a major holiday in Japan.

As mentioned in this comment, comtypes==1.4.6 would be the last version to support Python 3.7.

@forderud
Copy link
Contributor

I am planning to release comtypes==1.4.6 in the second week of August, probably on Monday morning (Japan time).
I am avoiding the third week of August because it coincides with a major holiday in Japan.

That's great! Looking forward to the release :-)

@junkmd
Copy link
Collaborator Author

junkmd commented Aug 4, 2024

comtypes==1.4.6 is released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working typing related to Python static typing system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

comtypes.client.GetModule fails on QWidget based tlb
2 participants