-
Notifications
You must be signed in to change notification settings - Fork 844
Fix DispatchWithEvents and WithEvents throw on 2nd call #2491
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
Fix DispatchWithEvents and WithEvents throw on 2nd call #2491
Conversation
com/win32com/test/testPyComTest.py
Outdated
|
|
||
| # Ensure that if it has already been dispatched, the base classes are the same. | ||
| o2_again = win32com.client.DispatchWithEvents(o, RandomEventHandler) | ||
| assert o2._obj_.__class__.__bases__ == o2_again._obj_.__class__.__bases__ | ||
| handler_again = win32com.client.WithEvents(o, RandomEventHandler) | ||
| assert handler.__class__.__bases__ == handler_again.__class__.__bases__ | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In hindsight, this is already tested by the lines above. So it's really just that the test doesn't run on CI...
| # Ensure that if it has already been dispatched, the base classes are the same. | |
| o2_again = win32com.client.DispatchWithEvents(o, RandomEventHandler) | |
| assert o2._obj_.__class__.__bases__ == o2_again._obj_.__class__.__bases__ | |
| handler_again = win32com.client.WithEvents(o, RandomEventHandler) | |
| assert handler.__class__.__bases__ == handler_again.__class__.__bases__ |
That seems bad.
huh - I thought that issue was more about the fact that the shell COM tests were not running on CI - is this suggesting no com tests are running on CI at all? We should certainly be able to run some. |
I haven't yet really looked into it, but I added some tests without fixing the issue here: Avasam#7 About not being able to run the tests locally, I deleted my venv, re-installed pywin32 globally, opened pwsh as admin, run the postinstall script, then tried running the test directly from the test folder. Now I get: Edit: Drilling down into where exactly it's failing for me, and it's basically this line: is |
|
About the reason the CI doesn't run these tests, I think it's because pywin32/com/win32com/test/testall.py Lines 179 to 191 in 03e65bc
pywin32/win32/scripts/pywin32_testall.py Lines 87 to 93 in 03e65bc
|
Yeah, that's frustrating :( We should probably work out how to build it in CI.
That seems like a decision which aged poorly :) |
|
I opened #2492 to track automated testing. At least this PR can be merged on it's own. I manually tested the MRE from the original issue (which is just a copy-paste of the docstring): just run the same |
CHANGES.txt
Outdated
| * Drop support for Vista, set Windows 7 as the minimal Windows version. (#, @Avasam) | ||
| * Fixed a regression where `win32com.client.DispatchWithEvents` and win32com.client.WithEvents` would throw a `TypeError` on the second call (#2491, @Avasam) | ||
| * Drop support for Vista, set Windows 7 as the minimal Windows version. (#2487, @Avasam) | ||
| * Restores many IIDs in `win32com(ext).shell.shell`. See #2486 for details. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation of this line looks wrong now there are other entries - should it be dedented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant for it to be a precision. But I could rewrite as "2 entries, added by the same changeset" like this:
| * Restores many IIDs in `win32com(ext).shell.shell`. See #2486 for details. | |
| * Restored many IIDs in `win32com(ext).shell.shell`. See #2486 for details. (#2487, @Avasam) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That "sub item" is more important imo - so maybe it should also move up and note it's a regression? code using win32com.shell is likely broken, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to reorganize the changelog to your likings if you want keep more important stuff at the top. You have the final say on those before releases ^^
…tps://github.com/Avasam/pywin32 into fix-DispatchWithEvents-and-WithEvents-regression
| if disp_class is None: | ||
| raise TypeError(error_msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explanation for moving this check only in the else branch:
It's not possible for disp_class to be None after the if branch.
mhammond
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks - looks good with a change to the log
We probably need a way to either incrementally add support for this, or give up on the idea - I'm not going to want to change a ton of code with the possibility of regressions just to possibly avoid further future regressions. Is there literally no way we could have added type annotations and checking to just the code that was changed here, or would we have needed to also touch other unrelated code at the same time? |
With mypy I'm adding checking incrementally by having mypy only check annotated functions (by default mypy only check functions it considers typed, and a method is considered typed when it's fully annotated). For pyright, it's not as flexible to decide what's checked. I can disable a check globally (or make it a warning). Or disable in specific files/modules/folders. Which is what I've done, and some checks will only require a few fixes to be re-enabled. Some may never be enabled either because of code that's too dynamic, or because there's too many violations. I'd like to see the public python API typed, and tested. (demos and tests files are also great to test the usage of the type annotations). Fixing stuff along the way. |
Maybe we should give up on adding more pyright support for now? While I'm generally supportive of adding type annotations etc, I'm not in favour of changing code just to keep these checkers happy unless that code is actually being changed for some other good reason. IOW, changing code just to keep the checkers happy has more risks than benefits IMO.
Similarly, I fully support fixing actual problems, but not so much for fixing theoretical problems. The fact a type checker says 15 year old code might have a problem is only interesting to me when we can identify a case where it is actually a problem. eg, maybe such a checker could indicate a place where a new test makes sense that demonstrates the problem. But changing code which is working fine just because some tool isn't smart enough to know what's a real problem vs which is not doesn't appeal and is a great path to regressions. I understand things are more subtle than I'm making them sound, but it's probably valuable to make my thinking clear around some of these proposed changes |
Fixes #2489
Obligatory "this would've been caught by pyright
reportGeneralTypeIssues" (but there's still like a thousand of those, so I'm far from enabling it)Easier to review by hiding whitespaces.
Added tests to cover the case where it's already been dispatched.But as we found out in #2467 , these tests aren't run on the CI, and I'm unable to run it locally either: