-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-106727: Add __module__
check for inspect.getsource(cls)
#106968
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
Conversation
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.
Can we add a test that fails without this fix?
This doesn't fix the case I mentioned (metaclass and class using it, both with the same name and in the same module), but it does fix the case where the metaclass is in a different module and the line numbers just happen to collide with another class of the same name.
I'm not seeing a clear way to fix the "metaclass with same name" case, and I'm also not really worried about it.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Oops, this comment crossed with my review. I think skipping news is fine, but I think we should have a test, even though it requires additional files. Subtle cases like this will break again in future refactors if there's no test. If it's worth fixing, it's worth testing. |
Fixed the style and added the test case - used a temporary directory for the files so I don't need to add extra files to the source code. Without the new check, the code would've found the first class as the line number of method borrowed from the other module happens to be inside the first class defined in Confirmed that the test would fail without the new check. |
Co-authored-by: Carl Meyer <[email protected]>
In method heuristics, make sure the method we check against comes from the same file as the class. Fixed the issue from #106815
inspect.getsource
(findsource
) not working as expected when duplicate class is used #106727