diff --git a/test-data/packages/typedpkg_ns/setup.py b/test-data/packages/typedpkg_ns_a/setup.py similarity index 50% rename from test-data/packages/typedpkg_ns/setup.py rename to test-data/packages/typedpkg_ns_a/setup.py index 9285e89104bbd..3dab731cada93 100644 --- a/test-data/packages/typedpkg_ns/setup.py +++ b/test-data/packages/typedpkg_ns_a/setup.py @@ -1,10 +1,10 @@ -from setuptools import setup, find_packages +from setuptools import setup setup( name='typedpkg_namespace.alpha', version='1.0.0', - packages=find_packages(), namespace_packages=['typedpkg_ns'], zip_safe=False, - package_data={'typedpkg_ns.ns': ['py.typed']} + package_data={'typedpkg_ns.a': ['py.typed']}, + packages=['typedpkg_ns.a'], ) diff --git a/test-data/packages/typedpkg_ns/typedpkg_ns/__init__.py b/test-data/packages/typedpkg_ns_a/typedpkg_ns/__init__.py similarity index 100% rename from test-data/packages/typedpkg_ns/typedpkg_ns/__init__.py rename to test-data/packages/typedpkg_ns_a/typedpkg_ns/__init__.py diff --git a/test-data/packages/typedpkg_ns/typedpkg_ns/ns/__init__.py b/test-data/packages/typedpkg_ns_a/typedpkg_ns/a/__init__.py similarity index 100% rename from test-data/packages/typedpkg_ns/typedpkg_ns/ns/__init__.py rename to test-data/packages/typedpkg_ns_a/typedpkg_ns/a/__init__.py diff --git a/test-data/packages/typedpkg_ns/typedpkg_ns/ns/bbb.py b/test-data/packages/typedpkg_ns_a/typedpkg_ns/a/bbb.py similarity index 100% rename from test-data/packages/typedpkg_ns/typedpkg_ns/ns/bbb.py rename to test-data/packages/typedpkg_ns_a/typedpkg_ns/a/bbb.py diff --git a/test-data/packages/typedpkg_ns/typedpkg_ns/ns/py.typed b/test-data/packages/typedpkg_ns_a/typedpkg_ns/a/py.typed similarity index 100% rename from test-data/packages/typedpkg_ns/typedpkg_ns/ns/py.typed rename to test-data/packages/typedpkg_ns_a/typedpkg_ns/a/py.typed diff --git a/test-data/packages/typedpkg_ns_b-stubs/setup.py b/test-data/packages/typedpkg_ns_b-stubs/setup.py new file mode 100644 index 0000000000000..a5d7df83eeea6 --- /dev/null +++ b/test-data/packages/typedpkg_ns_b-stubs/setup.py @@ -0,0 +1,14 @@ +""" +This setup file installs packages to test mypy's PEP 561 implementation +""" + +from distutils.core import setup + +setup( + name='typedpkg_ns_b-stubs', + author="The mypy team", + version='0.1', + namespace_packages=['typedpkg_ns-stubs'], + package_data={'typedpkg_ns-stubs.b': ['__init__.pyi', 'bbb.pyi']}, + packages=['typedpkg_ns-stubs.b'], +) diff --git a/test-data/packages/typedpkg_ns_b-stubs/typedpkg_ns-stubs/b/__init__.pyi b/test-data/packages/typedpkg_ns_b-stubs/typedpkg_ns-stubs/b/__init__.pyi new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/test-data/packages/typedpkg_ns_b-stubs/typedpkg_ns-stubs/b/bbb.pyi b/test-data/packages/typedpkg_ns_b-stubs/typedpkg_ns-stubs/b/bbb.pyi new file mode 100644 index 0000000000000..e00e9e52c05ff --- /dev/null +++ b/test-data/packages/typedpkg_ns_b-stubs/typedpkg_ns-stubs/b/bbb.pyi @@ -0,0 +1 @@ +def bf(a: bool) -> bool: ... diff --git a/test-data/packages/typedpkg_ns_b/setup.py b/test-data/packages/typedpkg_ns_b/setup.py new file mode 100644 index 0000000000000..4f0d0d954a735 --- /dev/null +++ b/test-data/packages/typedpkg_ns_b/setup.py @@ -0,0 +1,10 @@ +from setuptools import setup + +setup( + name='typedpkg_namespace.beta', + version='1.0.0', + namespace_packages=['typedpkg_ns'], + zip_safe=False, + package_data={'typedpkg_ns.b': []}, + packages=['typedpkg_ns.b'], +) diff --git a/test-data/packages/typedpkg_ns_b/typedpkg_ns/__init__.py b/test-data/packages/typedpkg_ns_b/typedpkg_ns/__init__.py new file mode 100644 index 0000000000000..3ac255b8a5772 --- /dev/null +++ b/test-data/packages/typedpkg_ns_b/typedpkg_ns/__init__.py @@ -0,0 +1,2 @@ +# namespace pkg +__import__("pkg_resources").declare_namespace(__name__) diff --git a/test-data/packages/typedpkg_ns_b/typedpkg_ns/b/__init__.py b/test-data/packages/typedpkg_ns_b/typedpkg_ns/b/__init__.py new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/test-data/packages/typedpkg_ns_b/typedpkg_ns/b/bbb.py b/test-data/packages/typedpkg_ns_b/typedpkg_ns/b/bbb.py new file mode 100644 index 0000000000000..f10802daace92 --- /dev/null +++ b/test-data/packages/typedpkg_ns_b/typedpkg_ns/b/bbb.py @@ -0,0 +1,2 @@ +def bf(a): + return not a diff --git a/test-data/unit/pep561.test b/test-data/unit/pep561.test index 033d0c52c5ae3..02c5bf5146124 100644 --- a/test-data/unit/pep561.test +++ b/test-data/unit/pep561.test @@ -119,10 +119,10 @@ reveal_type(a) testTypedPkgSimpleEditableEgg.py:5: note: Revealed type is "builtins.tuple[builtins.str]" [case testTypedPkgNamespaceImportFrom] -# pkgs: typedpkg, typedpkg_ns +# pkgs: typedpkg, typedpkg_ns_a from typedpkg.pkg.aaa import af -from typedpkg_ns.ns.bbb import bf -from typedpkg_ns.ns.dne import dne +from typedpkg_ns.a.bbb import bf +from typedpkg_ns.a.dne import dne af("abc") bf(False) @@ -132,16 +132,16 @@ af(False) bf(2) dne("abc") [out] -testTypedPkgNamespaceImportFrom.py:4: error: Cannot find implementation or library stub for module named "typedpkg_ns.ns.dne" +testTypedPkgNamespaceImportFrom.py:4: error: Cannot find implementation or library stub for module named "typedpkg_ns.a.dne" testTypedPkgNamespaceImportFrom.py:4: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports testTypedPkgNamespaceImportFrom.py:10: error: Argument 1 to "af" has incompatible type "bool"; expected "str" testTypedPkgNamespaceImportFrom.py:11: error: Argument 1 to "bf" has incompatible type "int"; expected "bool" [case testTypedPkgNamespaceImportAs] -# pkgs: typedpkg, typedpkg_ns +# pkgs: typedpkg, typedpkg_ns_a import typedpkg.pkg.aaa as nm; af = nm.af -import typedpkg_ns.ns.bbb as am; bf = am.bf -from typedpkg_ns.ns.dne import dne +import typedpkg_ns.a.bbb as am; bf = am.bf +from typedpkg_ns.a.dne import dne af("abc") bf(False) @@ -151,16 +151,16 @@ af(False) bf(2) dne("abc") [out] -testTypedPkgNamespaceImportAs.py:4: error: Cannot find implementation or library stub for module named "typedpkg_ns.ns.dne" +testTypedPkgNamespaceImportAs.py:4: error: Cannot find implementation or library stub for module named "typedpkg_ns.a.dne" testTypedPkgNamespaceImportAs.py:4: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports testTypedPkgNamespaceImportAs.py:10: error: Argument 1 has incompatible type "bool"; expected "str" testTypedPkgNamespaceImportAs.py:11: error: Argument 1 has incompatible type "int"; expected "bool" [case testTypedPkgNamespaceRegImport] -# pkgs: typedpkg, typedpkg_ns +# pkgs: typedpkg, typedpkg_ns_a import typedpkg.pkg.aaa; af = typedpkg.pkg.aaa.af -import typedpkg_ns.ns.bbb; bf = typedpkg_ns.ns.bbb.bf -from typedpkg_ns.ns.dne import dne +import typedpkg_ns.a.bbb; bf = typedpkg_ns.a.bbb.bf +from typedpkg_ns.a.dne import dne af("abc") bf(False) @@ -171,7 +171,7 @@ bf(2) dne("abc") [out] -testTypedPkgNamespaceRegImport.py:4: error: Cannot find implementation or library stub for module named "typedpkg_ns.ns.dne" +testTypedPkgNamespaceRegImport.py:4: error: Cannot find implementation or library stub for module named "typedpkg_ns.a.dne" testTypedPkgNamespaceRegImport.py:4: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports testTypedPkgNamespaceRegImport.py:10: error: Argument 1 has incompatible type "bool"; expected "str" testTypedPkgNamespaceRegImport.py:11: error: Argument 1 has incompatible type "int"; expected "bool" @@ -188,9 +188,36 @@ import a a.py:1: error: Unsupported operand types for + ("int" and "str") [case testTypedPkgNamespaceRegFromImportTwice] -# pkgs: typedpkg_ns -from typedpkg_ns import ns +# pkgs: typedpkg_ns_a +from typedpkg_ns import a -- dummy should trigger a second iteration [file dummy.py.2] [out] [out2] + +[case testNamespacePkgWStubs] +# pkgs: typedpkg_ns_a, typedpkg_ns_b, typedpkg_ns_b-stubs +import typedpkg_ns.a.bbb as a +import typedpkg_ns.b.bbb as b +a.bf(False) +b.bf(False) +a.bf(1) +b.bf(1) +[out] +testNamespacePkgWStubs.py:3: error: Skipping analyzing "typedpkg_ns.b.bbb": found module but no type hints or library stubs +testNamespacePkgWStubs.py:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports +testNamespacePkgWStubs.py:3: error: Skipping analyzing "typedpkg_ns.b": found module but no type hints or library stubs +testNamespacePkgWStubs.py:6: error: Argument 1 to "bf" has incompatible type "int"; expected "bool" + +[case testNamespacePkgWStubsWithNamespacePackagesFlag] +# pkgs: typedpkg_ns_a, typedpkg_ns_b, typedpkg_ns_b-stubs +# flags: --namespace-packages +import typedpkg_ns.a.bbb as a +import typedpkg_ns.b.bbb as b +a.bf(False) +b.bf(False) +a.bf(1) +b.bf(1) +[out] +testNamespacePkgWStubsWithNamespacePackagesFlag.py:7: error: Argument 1 to "bf" has incompatible type "int"; expected "bool" +testNamespacePkgWStubsWithNamespacePackagesFlag.py:8: error: Argument 1 to "bf" has incompatible type "int"; expected "bool"