8000 Namespace packages (PEP 420) by gvanrossum · Pull Request #5691 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Namespace packages (PEP 420) #5691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Oct 3, 2018
Prev Previous commit
Next Next commit
Add tests for namespace packages
  • Loading branch information
Guido van Rossum committed Sep 29, 2018
commit ecac1b5dd8675121b61770bc95b46b8ccadead77
49 changes: 49 additions & 0 deletions test-data/unit/check-modules.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-- Type checker test cases dealing with modules and imports.
-- Towards the end there are tests for PEP 420 (namespace packages, i.e. __init__.py-less packages).

[case testAccessImportedDefinitions]
import m
Expand Down Expand Up @@ -2525,3 +2526,51 @@ def __radd__(self) -> int: ...

[case testFunctionWithInPlaceDunderName]
def __iadd__(self) -> int: ...

-- Tests for PEP 420 namespace packages.
[case testClassicPackage]
from foo.bar import x
[file foo/__init__.py]
# empty
[file foo/bar.py]
x = 0

[case testClassicNotPackage]
from foo.bar import x
[file foo/bar.py]
x = 0
[out]
main:1: error: Cannot find module named 'foo.bar'
main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help)

[case testNamespacePackage]
# flags: --namespace-packages
from foo.bar import x
[file foo/bar.py]
x = 0

[case testNamespacePackageWithMypyPath]
# flags: --namespace-packages --config-file tmp/mypy.ini
from foo.bax import x
from foo.bay import y
from foo.baz import z
[file xx/foo/bax.py]
x = 0
[file yy/foo/bay.py]
y = 0
[file foo/baz.py]
z = 0
[file mypy.ini]
[[mypy]
mypy_path = tmp/xx, tmp/yy

[case testClassicPackageIgnoresEarlierNamespacePackage]
# flags: --namespace-packages --config-file tmp/mypy.ini
from foo.bar import y
[file xx/foo/bar.py]
[file yy/foo/bar.py]
y = 0
[file yy/foo/__init__.py]
[file mypy.ini]
[[mypy]
mypy_path = tmp/xx, tmp/yy
0