Debian Codegraph @

test-data/unit/fine-grained-follow-imports.test

raw
1 -- Test cases for --follow-imports=normal in fine-grained incremental mode.
2 --
3 -- Note that the implementation is mostly separate from normal incremental mode.
4
5 [case testFollowImportsNormalBasic]
6 # flags: --follow-imports=normal
7 # cmd: mypy main.py a.py
8
9 [file main.py]
10 import a
11 a.f()
12
13 [file a.py]
14 def f() -> None: pass
15
16 [file a.py.2]
17 def f(x: str) -> None: pass
18
19 [file a.py.3]
20 def f() -> None: pass
21
22 [out]
23 ==
24 main.py:2: error: Missing positional argument "x" in call to "f"
25 ==
26
27 [case testFollowImportsNormalAddSuppressed]
28 # flags: --follow-imports=normal
29 # cmd: mypy main.py
30
31 [file main.py]
32 import a
33 a.f()
34
35 [file a.py.2]
36 def f(x: str) -> None: pass
37
38 [file a.py.3]
39 def f() -> None: pass
40
41 [out]
42 main.py:1: error: Cannot find implementation or library stub for module named "a"
43 main.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
44 ==
45 main.py:2: error: Missing positional argument "x" in call to "f"
46 ==
47
48 [case testFollowImportsNormalAddSuppressed2]
49 # flags: --follow-imports=normal
50 # cmd: mypy main.py
51
52 [file main.py]
53 import a # type: ignore
54 a.f()
55
56 [file a.py.2]
57 def f(x: str) -> None: pass
58
59 [file a.py.3]
60 def f() -> None: pass
61
62 [out]
63 ==
64 main.py:2: error: Missing positional argument "x" in call to "f"
65 ==
66
67 [case testFollowImportsNormalAddSuppressed3]
68 # flags: --follow-imports=normal
69 # cmd: mypy main.py
70
71 [file main.py]
72 import a
73 a.b.f()
74
75 [file a.py.2]
76 import b
77
78 [file b.py.2]
79 def f(x: str) -> None: pass
80
81 [file b.py.3]
82 def f() -> None: pass
83
84 [out]
85 main.py:1: error: Cannot find implementation or library stub for module named "a"
86 main.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
87 ==
88 main.py:2: error: Missing positional argument "x" in call to "f"
89 ==
90
91 [case testFollowImportsNormalEditingFileBringNewModule]
92 # flags: --follow-imports=normal
93 # cmd: mypy main.py
94
95 [file main.py]
96
97 [file main.py.2]
98 import a
99 a.f()
100
101 [file a.py.2]
102 def f(x: str) -> None: pass
103
104 [file a.py.3]
105 def f() -> None: pass
106
107 [out]
108 ==
109 main.py:2: error: Missing positional argument "x" in call to "f"
110 ==
111
112 [case testFollowImportsNormalEditingFileBringNewModules]
113 # flags: --follow-imports=normal
114 # cmd: mypy main.py
115
116 [file main.py]
117
118 [file main.py.2]
119 import a
120 a.b.f()
121
122 [file a.py.2]
123 import b
124
125 [file b.py.2]
126 def f(x: str) -> None: pass
127
128 [file b.py.3]
129 def f() -> None: pass
130
131 [out]
132 ==
133 main.py:2: error: Missing positional argument "x" in call to "f"
134 ==
135
136 [case testFollowImportsNormalDuringStartup]
137 # flags: --follow-imports=normal
138 # cmd: mypy main.py
139
140 [file main.py]
141 import a
142 a.f()
143
144 [file a.py]
145 def f() -> None: pass
146
147 [file a.py.2]
148 def f(x: str) -> None: pass
149
150 [out]
151 ==
152 main.py:2: error: Missing positional argument "x" in call to "f"
153
154 [case testFollowImportsNormalDuringStartup2]
155 # flags: --follow-imports=normal
156 # cmd: mypy main.py
157
158 [file main.py]
159 import a
160 a.f()
161
162 [file a.py]
163 def f(x: str) -> None: pass
164
165 [file a.py.2]
166 def f() -> None: pass
167
168 [out]
169 main.py:2: error: Missing positional argument "x" in call to "f"
170 ==
171
172 [case testFollowImportsNormalDuringStartup3]
173 # flags: --follow-imports=normal
174 # cmd: mypy main.py
175
176 [file main.py]
177 import a
178 a.g()
179
180 [file a.py]
181 import b
182 g = b.f
183
184 [file b.py]
185 def f(x: str) -> None: pass
186
187 [file b.py.2]
188 def f() -> None: pass
189
190 [file a.py.3]
191 g = 0
192
193 [out]
194 main.py:2: error: Too few arguments
195 ==
196 ==
197 main.py:2: error: "int" not callable
198
199 [case testFollowImportsNormalDeleteFile1]
200 # flags: --follow-imports=normal
201 # cmd: mypy main.py a.py
202 # cmd2: mypy main.py
203 # cmd3: mypy main.py a.py
204
205 [file main.py]
206 import a
207 a.f()
208
209 [file a.py]
210 def f() -> None: pass
211
212 [delete a.py.2]
213
214 [file a.py.3]
215 def f(x: str) -> None: pass
216
217 [out]
218 ==
219 main.py:1: error: Cannot find implementation or library stub for module named "a"
220 main.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
221 ==
222 main.py:2: error: Missing positional argument "x" in call to "f"
223
224 [case testFollowImportsNormalDeleteFile2]
225 # flags: --follow-imports=normal
226 # cmd: mypy main.py
227
228 [file main.py]
229 import a
230 a.f()
231
232 [file a.py]
233 def f() -> None: pass
234
235 [delete a.py.2]
236
237 [file a.py.3]
238 def f(x: str) -> None: pass
239
240 [out]
241 ==
242 main.py:1: error: Cannot find implementation or library stub for module named "a"
243 main.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
244 ==
245 main.py:2: error: Missing positional argument "x" in call to "f"
246
247 [case testFollowImportsNormalDeleteFile3]
248 # flags: --follow-imports=normal
249 # cmd: mypy main.py
250
251 [file main.py]
252 import a # type: ignore
253 a.f()
254
255 [file a.py]
256 def f() -> None: pass
257
258 [delete a.py.2]
259
260 [file a.py.3]
261 def f(x: str) -> None: pass
262
263 [out]
264 ==
265 ==
266 main.py:2: error: Missing positional argument "x" in call to "f"
267
268 [case testFollowImportsNormalDeleteFile4]
269 # flags: --follow-imports=normal
270 # cmd: mypy main.py
271
272 [file main.py]
273 import a
274
275 [file a.py]
276 1()
277
278 [file main.py.2]
279 # don't import a
280
281 [file main.py.3]
282 import a
283
284 [out]
285 a.py:1: error: "int" not callable
286 ==
287 ==
288 a.py:1: error: "int" not callable
289
290 [case testFollowImportsNormalDeleteFile5]
291 # flags: --follow-imports=normal
292 # cmd: mypy main.py
293
294 [file main.py]
295 import a
296
297 [file a.py]
298 import b
299
300 [file b.py]
301 1()
302
303 [file a.py.2]
304 # don't import b
305
306 [file a.py.3]
307 import b
308
309 [out]
310 b.py:1: error: "int" not callable
311 ==
312 ==
313 b.py:1: error: "int" not callable
314
315 [case testFollowImportsNormalDeleteFile6]
316 # flags: --follow-imports=normal
317 # cmd: mypy main.py
318
319 [file main.py]
320 import a
321
322 [file a.py]
323 import b
324
325 [file b.py]
326 1()
327
328 [delete a.py.2]
329
330 [file a.py.3]
331 import b
332
333 [out]
334 b.py:1: error: "int" not callable
335 ==
336 main.py:1: error: Cannot find implementation or library stub for module named "a"
337 main.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
338 ==
339 b.py:1: error: "int" not callable
340
341 [case testFollowImportsNormalDeleteFile7]
342 # flags: --follow-imports=normal
343 # cmd: mypy main.py
344
345 [file main.py]
346 import a
347
348 [file a.py]
349 import b
350 from c import f
351
352 [file b.py]
353 from d import *
354
355 [file c.py]
356 import a
357 def f(): pass
358 1()
359
360 [file d.py]
361 1()
362
363 [file main.py.2]
364
365 [file main.py.3]
366 import d
367
368 [out]
369 d.py:1: error: "int" not callable
370 c.py:3: error: "int" not callable
371 ==
372 ==
373 d.py:1: error: "int" not callable
374
375 [case testFollowImportsNormalKeepAliveViaNewFile]
376 # flags: --follow-imports=normal
377 # cmd: mypy main.py
378
379 [file main.py]
380 import a
381
382 [file a.py]
383 import b
384
385 [file b.py]
386 1()
387
388 [file a.py.2]
389 import c
390
391 [file c.py.2]
392 import d
393
394 [file d.py.2]
395 import b
396
397 [out]
398 b.py:1: error: "int" not callable
399 ==
400 b.py:1: error: "int" not callable
401
402 [case testFollowImportsNormalPackage-only_when_nocache]
403 # flags: --follow-imports=normal
404 # cmd: mypy main.py
405
406 [file main.py]
407 import p.m # type: ignore
408
409 p.m.f()
410
411 [file p/__init__.py.2]
412
413 [file p/m.py.2]
414 def f(x: str) -> None: pass
415
416 1()
417
418 [file p/m.py.3]
419 def f(x: str) -> None: pass
420
421 [delete p.4]
422
423 [out]
424 ==
425 p/m.py:3: error: "int" not callable
426 main.py:3: error: Missing positional argument "x" in call to "f"
427 ==
428 main.py:3: error: Missing positional argument "x" in call to "f"
429 ==
430
431 [case testFollowImportsNormalPackage2-only_when_cache]
432 # flags: --follow-imports=normal
433 # cmd: mypy main.py
434
435 [file main.py]
436 import p.m # type: ignore
437
438 p.m.f()
439
440 [file p/__init__.py.2]
441
442 [file p/m.py.2]
443 def f(x: str) -> None: pass
444
445 1()
446
447 [delete p.3]
448
449 [out]
450 ==
451 main.py:3: error: Missing positional argument "x" in call to "f"
452 p/m.py:3: error: "int" not callable
453 ==
454
455 [case testFollowImportsNormalPackageInitFile1]
456 # flags: --follow-imports=normal
457 # cmd: mypy main.py
458
459 [file main.py]
460 import p1.m
461 from p2 import m
462
463 [file p1/__init__.py.2]
464 1()
465
466 [file p1/m.py.2]
467
468 [file p2/__init__.py.3]
469 ''()
470
471 [file p2/m.py.3]
472
473 [out]
474 main.py:1: error: Cannot find implementation or library stub for module named "p1.m"
475 main.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
476 main.py:1: error: Cannot find implementation or library stub for module named "p1"
477 main.py:2: error: Cannot find implementation or library stub for module named "p2"
478 ==
479 main.py:2: error: Cannot find implementation or library stub for module named "p2"
480 main.py:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
481 p1/__init__.py:1: error: "int" not callable
482 ==
483 p1/__init__.py:1: error: "int" not callable
484 p2/__init__.py:1: error: "str" not callable
485
486 [case testFollowImportsNormalPackageInitFile2]
487 # flags: --follow-imports=normal
488 # cmd: mypy main.py
489
490 [file main.py]
491 from p import m
492
493 [file p/__init__.py.2]
494
495 [file p/m.py.3]
496 ''()
497
498 [out]
499 main.py:1: error: Cannot find implementation or library stub for module named "p"
500 main.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
501 ==
502 main.py:1: error: Module "p" has no attribute "m"
503 ==
504 p/m.py:1: error: "str" not callable
505
506 [case testFollowImportsNormalPackageInitFile3]
507 # flags: --follow-imports=normal
508 # cmd: mypy main.py
509
510 [file main.py]
511 import p1.s1.m
512 from p2.s2 import m
513 p1.s1.m.f()
514 m.f(1)
515
516 [file p1/__init__.py.2]
517
518 [file p1/s1/__init__.py.2]
519
520 [file p1/s1/m.py.2]
521 def f(x: str) -> None: pass
522
523 [file p2/__init__.py.3]
524
525 [file p2/s2/__init__.py.3]
526
527 [file p2/s2/m.py.3]
528 def f() -> None: pass
529
530 [out]
531 main.py:1: error: Cannot find implementation or library stub for module named "p1.s1.m"
532 main.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
533 main.py:1: error: Cannot find implementation or library stub for module named "p1.s1"
534 main.py:1: error: Cannot find implementation or library stub for module named "p1"
535 main.py:2: error: Cannot find implementation or library stub for module named "p2.s2"
536 ==
537 main.py:2: error: Cannot find implementation or library stub for module named "p2.s2"
538 main.py:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
539 main.py:3: error: Missing positional argument "x" in call to "f"
540 ==
541 main.py:3: error: Missing positional argument "x" in call to "f"
542 main.py:4: error: Too many arguments for "f"
543
544 [case testFollowImportsNormalPackageInitFile4-only_when_cache]
545 # flags: --follow-imports=normal
546 # cmd: mypy main.py
547
548 [file main.py]
549 import p1.m # type: ignore
550 from p2 import m # type: ignore
551
552 [file p1/__init__.py.2]
553 1()
554
555 [file p1/m.py.2]
556 ''()
557
558 [file p2/__init__.py.3]
559 ''()
560
561 [file p2/m.py.3]
562
563 [out]
564 ==
565 p1/__init__.py:1: error: "int" not callable
566 p1/m.py:1: error: "str" not callable
567 ==
568 p1/__init__.py:1: error: "int" not callable
569 p1/m.py:1: error: "str" not callable
570 p2/__init__.py:1: error: "str" not callable
571
572 [case testFollowImportsNormalSubmoduleCreatedWithImportInFunction]
573 # flags: --follow-imports=normal
574 # cmd: mypy main.py
575
576 [file main.py]
577 def f() -> None:
578 from p import m
579
580 [file p/__init__.py.2]
581 1()
582
583 [file p/m.py.2]
584 ''()
585
586 [out]
587 main.py:2: error: Cannot find implementation or library stub for module named "p"
588 main.py:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
589 ==
590 p/__init__.py:1: error: "int" not callable
591 p/m.py:1: error: "str" not callable
592
593 [case testFollowImportsNormalPackageInitFileStub]
594 # flags: --follow-imports=normal
595 # cmd: mypy main.py
596
597 [file main.py]
598 from p import m
599
600 [file p/__init__.pyi.2]
601 1()
602
603 [file p/m.pyi.2]
604 ''()
605
606 [file p/mm.pyi.3]
607 x x x
608
609 [out]
610 main.py:1: error: Cannot find implementation or library stub for module named "p"
611 main.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
612 ==
613 p/__init__.pyi:1: error: "int" not callable
614 p/m.pyi:1: error: "str" not callable
615 ==
616 p/__init__.pyi:1: error: "int" not callable
617 p/m.pyi:1: error: "str" not callable
618
619 [case testFollowImportsNormalNamespacePackages]
620 # flags: --follow-imports=normal --namespace-packages
621 # cmd: mypy main.py
622
623 [file main.py]
624 import p1.m1
625 import p2.m2
626
627 [file p1/m1.py]
628 1()
629
630 [file p2/m2.py.2]
631 ''()
632
633 [delete p2/m2.py.3]
634
635 [out]
636 p1/m1.py:1: error: "int" not callable
637 main.py:2: error: Cannot find implementation or library stub for module named "p2.m2"
638 main.py:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
639 main.py:2: error: Cannot find implementation or library stub for module named "p2"
640 ==
641 p1/m1.py:1: error: "int" not callable
642 p2/m2.py:1: error: "str" not callable
643 ==
644 p1/m1.py:1: error: "int" not callable
645 main.py:2: error: Cannot find implementation or library stub for module named "p2.m2"
646 main.py:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
647
648 [case testFollowImportsNormalNewFileOnCommandLine]
649 # flags: --follow-imports=normal
650 # cmd: mypy main.py
651 # cmd2: mypy main.py x.py
652
653 [file main.py]
654 1()
655
656 [file x.py.2]
657 ''()
658
659 [out]
660 main.py:1: error: "int" not callable
661 ==
662 main.py:1: error: "int" not callable
663 x.py:1: error: "str" not callable
664
665 [case testFollowImportsNormalSearchPathUpdate-only_when_nocache]
666 # flags: --follow-imports=normal
667 # cmd: mypy main.py
668 # cmd2: mypy main.py src/foo.py
669
670 [file main.py]
671
672 [file src/foo.py.2]
673 import bar
674 ''()
675
676 [file src/bar.py.2]
677 1()
678
679 [out]
680 ==
681 src/foo.py:2: error: "str" not callable
682 src/bar.py:1: error: "int" not callable
683
684 [case testFollowImportsNormalSearchPathUpdate2-only_when_cache]
685 # flags: --follow-imports=normal
686 # cmd: mypy main.py
687 # cmd2: mypy main.py src/foo.py
688
689 [file main.py]
690
691 [file src/foo.py.2]
692 import bar
693 ''()
694
695 [file src/bar.py.2]
696 1()
697
698 [out]
699 ==
700 src/foo.py:2: error: "str" not callable
701 src/bar.py:1: error: "int" not callable
702
703 [case testFollowImportsNormalSuppressedAffectsCachedFile-only_when_cache]
704 # flags: --follow-imports=normal
705 # cmd: mypy main.py
706
707 [file main.py]
708 from p import m # type: ignore
709 m.f(1)
710
711 [file p/__init__.py]
712
713 [file p/m.py.2]
714 # This change will trigger a cached file (main.py) through a suppressed
715 # submodule, resulting in additional errors in main.py.
716 def f() -> None: pass
717
718 [out]
719 ==
720 main.py:2: error: Too many arguments for "f"
721
722 [case testFollowImportsNormalMultipleImportedModulesSpecialCase]
723 # flags: --follow-imports=normal
724 # cmd: mypy main.py
725
726 [file main.py]
727 import pkg
728
729 [file pkg/__init__.py.2]
730 from . import mod1
731
732 [file pkg/mod1.py.2]
733 from . import mod2
734
735 [file pkg/mod2.py.2]
736
737 [out]
738 main.py:1: error: Cannot find implementation or library stub for module named "pkg"
739 main.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
740 ==
741
742 [case testFollowImportsNormalDeletePackage]
743 # flags: --follow-imports=normal
744 # cmd: mypy main.py
745
746 [file main.py]
747 import pkg
748
749 [file pkg/__init__.py]
750 from . import mod
751
752 [file pkg/mod.py]
753 from . import mod2
754 import pkg2
755
756 [file pkg/mod2.py]
757 from . import mod2
758 import pkg2
759
760 [file pkg2/__init__.py]
761 from . import mod3
762
763 [file pkg2/mod3.py]
764
765 [delete pkg/.2]
766 [delete pkg2/.2]
767
768 [out]
769 ==
770 main.py:1: error: Cannot find implementation or library stub for module named "pkg"
771 main.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
772
773 [case testNewImportCycleTypeVarBound]
774 # flags: --follow-imports=normal
775 # cmd: mypy main.py
776 # cmd2: mypy other.py
777
778 [file main.py]
779 # empty
780
781 [file other.py.2]
782 import trio
783
784 [file trio/__init__.py.2]
785 from typing import TypeVar
786 import trio
787 from . import abc as abc
788
789 T = TypeVar("T", bound=trio.abc.A)
790
791 [file trio/abc.py.2]
792 import trio
793 class A: ...
794 [out]
795 ==
796
797 [case testNewImportCycleTupleBase]
798 # flags: --follow-imports=normal
799 # cmd: mypy main.py
800 # cmd2: mypy other.py
801
802 [file main.py]
803 # empty
804
805 [file other.py.2]
806 import trio
807
808 [file trio/__init__.py.2]
809 from typing import TypeVar, Tuple
810 import trio
811 from . import abc as abc
812
813 class C(Tuple[trio.abc.A, trio.abc.A]): ...
814
815 [file trio/abc.py.2]
816 import trio
817 class A: ...
818 [builtins fixtures/tuple.pyi]
819 [out]
820 ==
821
822 [case testNewImportCycleTypedDict]
823 # flags: --follow-imports=normal
824 # cmd: mypy main.py
825 # cmd2: mypy other.py
826
827 [file main.py]
828 # empty
829
830 [file other.py.2]
831 import trio
832
833 [file trio/__init__.py.2]
834 from typing import TypedDict, TypeVar
835 import trio
836 from . import abc as abc
837
838 class C(TypedDict):
839 x: trio.abc.A
840 y: trio.abc.A
841
842 [file trio/abc.py.2]
843 import trio
844 class A: ...
845 [builtins fixtures/dict.pyi]
846 [typing fixtures/typing-typeddict.pyi]
847 [out]
848 ==