Skip to content

Fix incorrect signature suggestion from dmypy suggest when type name matches imported module name #18937

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

brianschubert
Copy link
Collaborator

Fixes #18935

Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

class bar: ... # name matches module name

[out]
() -> bar.bar

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is ~sorta problematic too as tools will interpret this as "I need to add from bar import bar" which will collide with the already imported bar name

Copy link
Collaborator Author

@brianschubert brianschubert Apr 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, not sure I follow. -> bar.bar would be a correct annotation here. If a tool decides to transform that into using -> bar with from bar import bar without checking if bar conflicts with another name in the same scope, that sounds like a problem with the tool, not with the suggestion mypy is supplying, no? Would another behavior be preferable?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mypy is really the unique place where that knowledge is -- a tool just applying suggestions would have a difficult time knowing what types the symbols are

in my original issue I had suggested (translating for this example) foo:bar.bar which would be the best suggestion without needing to add an import

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.

dmypy suggest gives wrong type (datetime vs datetime module)
2 participants