File tree 1 file changed +49
-0
lines changed
1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change 1
1
-- Type checker test cases dealing with modules and imports.
2
+ -- Towards the end there are tests for PEP 420 (namespace packages, i.e. __init__.py-less packages).
2
3
3
4
[case testAccessImportedDefinitions]
4
5
import m
@@ -2525,3 +2526,51 @@ def __radd__(self) -> int: ...
2525
2526
2526
2527
[case testFunctionWithInPlaceDunderName]
2527
2528
def __iadd__(self) -> int: ...
2529
+
2530
+ -- Tests for PEP 420 namespace packages.
2531
+ [case testClassicPackage]
2532
+ from foo.bar import x
2533
+ [file foo/__init__.py]
2534
+ # empty
2535
+ [file foo/bar.py]
2536
+ x = 0
2537
+
2538
+ [case testClassicNotPackage]
2539
+ from foo.bar import x
2540
+ [file foo/bar.py]
2541
+ x = 0
2542
+ [out]
2543
+ main:1: error: Cannot find module named 'foo.bar'
2544
+ main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help)
2545
+
2546
+ [case testNamespacePackage]
2547
+ # flags: --namespace-packages
2548
+ from foo.bar import x
2549
+ [file foo/bar.py]
2550
+ x = 0
2551
+
2552
+ [case testNamespacePackageWithMypyPath]
2553
+ # flags: --namespace-packages --config-file tmp/mypy.ini
2554
+ from foo.bax import x
2555
+ from foo.bay import y
2556
+ from foo.baz import z
2557
+ [file xx/foo/bax.py]
2558
+ x = 0
2559
+ [file yy/foo/bay.py]
2560
+ y = 0
2561
+ [file foo/baz.py]
2562
+ z = 0
2563
+ [file mypy.ini]
2564
+ [[mypy]
2565
+ mypy_path = tmp/xx, tmp/yy
2566
+
2567
+ [case testClassicPackageIgnoresEarlierNamespacePackage]
2568
+ # flags: --namespace-packages --config-file tmp/mypy.ini
2569
+ from foo.bar import y
2570
+ [file xx/foo/bar.py]
2571
+ [file yy/foo/bar.py]
2572
+ y = 0
2573
+ [file yy/foo/__init__.py]
2574
+ [file mypy.ini]
2575
+ [[mypy]
2576
+ mypy_path = tmp/xx, tmp/yy
You can’t perform that action at this time.
0 commit comments