Skip to content

Commit 357d99d

Browse files
committed
Add tests to stress test type references
1 parent 2915f05 commit 357d99d

File tree

2 files changed

+81
-3
lines changed

2 files changed

+81
-3
lines changed

mypy/indirection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
def extract_module_names(symbol_name: str) -> Iterable[str]:
13-
"""Returns the module and parent modules of a fully qualified symbol name."""
13+
"""Return the module and parent modules of a fully qualified symbol name."""
1414
if symbol_name is not None:
1515
while '.' in symbol_name:
1616
symbol_name = symbol_name.rsplit('.', 1)[0]

test-data/unit/check-incremental.test

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,18 +351,96 @@ import mod2.mod3 as mod3
351351
[file mod2/mod3/__init__.py]
352352
import mod2.mod3.mod4 as mod4
353353

354+
[file mod2/mod3/__init__.py.next]
355+
# Import is gone!
356+
354357
[file mod2/mod3/mod4.py]
355358
const = 3
356359

360+
[rechecked mod1, mod2, mod2.mod3]
361+
[stale mod2.mod3]
362+
[builtins fixtures/module.pyi]
363+
[out2]
364+
main:1: note: In module imported here:
365+
tmp/mod1.py:3: error: "module" has no attribute "mod4"
366+
367+
[case testIncrementalNestedBrokenCascadeWithType1]
368+
import mod1, mod2.mod3.mod5
369+
370+
[file mod1.py]
371+
import mod2
372+
def accept_int(x: int) -> None: pass
373+
def produce() -> mod2.CustomType:
374+
return mod2.CustomType()
375+
a = produce()
376+
accept_int(a.foo())
377+
378+
[file mod2/__init__.py]
379+
from mod2.mod3 import CustomType
380+
381+
[file mod2/mod3/__init__.py]
382+
from mod2.mod3.mod4 import CustomType
383+
357384
[file mod2/mod3/__init__.py.next]
358-
# Import is gone!
385+
# Import a different class that also happens to be called 'CustomType'
386+
from mod2.mod3.mod5 import CustomType
387+
def produce() -> CustomType:
388+
return CustomType()
389+
390+
[file mod2/mod3/mod4.py]
391+
class CustomType:
392+
def foo(self) -> int: return 1
393+
394+
[file mod2/mod3/mod5.py]
395+
class CustomType:
396+
def foo(self) -> str: return "a"
397+
398+
[rechecked mod1, mod2, mod2.mod3]
399+
[stale mod2, mod2.mod3]
400+
[builtins fixtures/module.pyi]
401+
[out1]
402+
[out2]
403+
main:1: note: In module imported here:
404+
tmp/mod1.py:6: error: Argument 1 to "accept_int" has incompatible type "str"; expected "int"
405+
406+
[case testIncrementalNestedBrokenCascadeWithType2]
407+
import mod1, mod2.mod3.mod5
408+
409+
[file mod1.py]
410+
from mod2 import produce
411+
def accept_int(x: int) -> None: pass
412+
a = produce()
413+
accept_int(a.foo())
414+
415+
[file mod2/__init__.py]
416+
from mod2.mod3 import produce
417+
418+
[file mod2/mod3/__init__.py]
419+
from mod2.mod3.mod4 import CustomType
420+
def produce() -> CustomType:
421+
return CustomType()
422+
423+
[file mod2/mod3/__init__.py.next]
424+
# Import a different class that also happens to be called 'CustomType'
425+
from mod2.mod3.mod5 import CustomType
426+
def produce() -> CustomType:
427+
return CustomType()
428+
429+
[file mod2/mod3/mod4.py]
430+
class CustomType:
431+
def foo(self) -> int: return 1
432+
433+
[file mod2/mod3/mod5.py]
434+
class CustomType:
435+
def foo(self) -> str: return "a"
359436

360437
[rechecked mod1, mod2, mod2.mod3]
361438
[stale mod2.mod3]
362439
[builtins fixtures/module.pyi]
440+
[out1]
363441
[out2]
364442
main:1: note: In module imported here:
365-
tmp/mod1.py:3: error: "module" has no attribute "mod4"
443+
tmp/mod1.py:4: error: Argument 1 to "accept_int" has incompatible type "str"; expected "int"
366444

367445
[case testIncrementalRemoteChange]
368446
import mod1

0 commit comments

Comments
 (0)