Fix incorrect signature suggestion from dmypy suggest when type name matches imported module name#18937
Conversation
|
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
hauntsaninja
left a comment
There was a problem hiding this comment.
Merging, since this is an improvement. We can try disambiguating with colon in another PR (I don't have much context on what all uses dmypy suggest and whether introducing colons would be a breaking change)
Fixes #18935