Skip to content

Commit 68bcdc3

Browse files
committed
Fix dmypy suggest detection of reexports
1 parent 454989f commit 68bcdc3

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

mypy/suggestions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ def visit_instance(self, t: Instance) -> str:
837837
if self.module:
838838
parts = obj.split(".") # need to split the object part if it is a nested class
839839
tree = self.graph[self.module].tree
840-
if tree and parts[0] in tree.names:
840+
if tree and parts[0] in tree.names and mod not in tree.names:
841841
mod = self.module
842842

843843
if (mod, obj) == ("builtins", "tuple"):

test-data/unit/fine-grained-suggest.test

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,36 @@ foo(B())
207207
(baz.B) -> Tuple[foo.A, foo:A.C]
208208
==
209209

210+
[case testSuggestReexportNamingNameMatchesModule1]
211+
# suggest: foo.foo
212+
[file foo.py]
213+
import bar
214+
def foo():
215+
return bar.bar()
216+
217+
[file bar.py]
218+
class bar: ... # name matches module name
219+
220+
[out]
221+
() -> bar.bar
222+
==
223+
224+
[case testSuggestReexportNamingNameMatchesModule2]
225+
# suggest: foo.foo
226+
[file foo.py]
227+
import bar
228+
import qux
229+
def foo():
230+
return qux.bar()
231+
232+
[file bar.py]
233+
[file qux.py]
234+
class bar: ... # name matches another module name
235+
236+
[out]
237+
() -> qux.bar
238+
==
239+
210240
[case testSuggestInferInit]
211241
# suggest: foo.Foo.__init__
212242
[file foo.py]

0 commit comments

Comments
 (0)