Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-106727: Add__module__ check forinspect.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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
carljm merged 3 commits intopython:mainfromgaogaotiantian:module-check-for-inspect
Jul 24, 2023

Conversation

gaogaotiantian
Copy link
Member

@gaogaotiantiangaogaotiantian commentedJul 21, 2023
edited
Loading

In method heuristics, make sure the method we check against comes from the same file as the class. Fixed the issue from#106815

@gaogaotiantian
Copy link
MemberAuthor

This fix is straightforward enough and is a supplement to#106815, so I skipped the news. If@carljm thinks the other way, I can add the news. Also do we want a test for it? It requires some delicate file line number conflict from two files.

carljm reacted with thumbs up emoji

Copy link
Member

@carljmcarljm left a 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.

@bedevere-bot
Copy link

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 phraseI have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@carljm
Copy link
Member

This fix is straightforward enough and is a supplement to#106815, so I skipped the news. If@carljm thinks the other way, I can add the news. Also do we want a test for it? It requires some delicate file line number conflict from two files.

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.

@gaogaotiantian
Copy link
MemberAuthor

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 ininspect_actual.

Confirmed that the test would fail without the new check.

Co-authored-by: Carl Meyer <carl@oddbird.net>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@carljmcarljmcarljm approved these changes

Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@gaogaotiantian@bedevere-bot@carljm

[8]ページ先頭

©2009-2025 Movatter.jp