Skip to content

Commit 80694de

Browse files
committed
Add testpep561 test
1 parent c2492e8 commit 80694de

File tree

13 files changed

+73
-17
lines changed

13 files changed

+73
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from setuptools import setup, find_packages
1+
from setuptools import setup
22

33
setup(
44
name='typedpkg_namespace.alpha',
55
version='1.0.0',
6-
packages=find_packages(),
76
namespace_packages=['typedpkg_ns'],
87
zip_safe=False,
9-
package_data={'typedpkg_ns.ns': ['py.typed']}
8+
package_data={'typedpkg_ns.a': ['py.typed']},
9+
packages=['typedpkg_ns.a'],
1010
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""
2+
This setup file installs packages to test mypy's PEP 561 implementation
3+
"""
4+
5+
from distutils.core import setup
6+
7+
setup(
8+
name='typedpkg_ns_b-stubs',
9+
author="The mypy team",
10+
version='0.1',
11+
namespace_packages=['typedpkg_ns-stubs'],
12+
package_data={'typedpkg_ns-stubs.b': ['__init__.pyi', 'bbb.pyi']},
13+
packages=['typedpkg_ns-stubs.b'],
14+
)

test-data/packages/typedpkg_ns_b-stubs/typedpkg_ns-stubs/b/__init__.pyi

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def bf(a: bool) -> bool: ...
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from setuptools import setup
2+
3+
setup(
4+
name='typedpkg_namespace.beta',
5+
version='1.0.0',
6+
namespace_packages=['typedpkg_ns'],
7+
zip_safe=False,
8+
package_data={'typedpkg_ns.b': []},
9+
packages=['typedpkg_ns.b'],
10+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# namespace pkg
2+
__import__("pkg_resources").declare_namespace(__name__)

test-data/packages/typedpkg_ns_b/typedpkg_ns/b/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def bf(a):
2+
return not a

test-data/unit/pep561.test

+41-14
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ reveal_type(a)
119119
testTypedPkgSimpleEditableEgg.py:5: note: Revealed type is "builtins.tuple[builtins.str]"
120120

121121
[case testTypedPkgNamespaceImportFrom]
122-
# pkgs: typedpkg, typedpkg_ns
122+
# pkgs: typedpkg, typedpkg_ns_a
123123
from typedpkg.pkg.aaa import af
124-
from typedpkg_ns.ns.bbb import bf
125-
from typedpkg_ns.ns.dne import dne
124+
from typedpkg_ns.a.bbb import bf
125+
from typedpkg_ns.a.dne import dne
126126

127127
af("abc")
128128
bf(False)
@@ -132,16 +132,16 @@ af(False)
132132
bf(2)
133133
dne("abc")
134134
[out]
135-
testTypedPkgNamespaceImportFrom.py:4: error: Cannot find implementation or library stub for module named "typedpkg_ns.ns.dne"
135+
testTypedPkgNamespaceImportFrom.py:4: error: Cannot find implementation or library stub for module named "typedpkg_ns.a.dne"
136136
testTypedPkgNamespaceImportFrom.py:4: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
137137
testTypedPkgNamespaceImportFrom.py:10: error: Argument 1 to "af" has incompatible type "bool"; expected "str"
138138
testTypedPkgNamespaceImportFrom.py:11: error: Argument 1 to "bf" has incompatible type "int"; expected "bool"
139139

140140
[case testTypedPkgNamespaceImportAs]
141-
# pkgs: typedpkg, typedpkg_ns
141+
# pkgs: typedpkg, typedpkg_ns_a
142142
import typedpkg.pkg.aaa as nm; af = nm.af
143-
import typedpkg_ns.ns.bbb as am; bf = am.bf
144-
from typedpkg_ns.ns.dne import dne
143+
import typedpkg_ns.a.bbb as am; bf = am.bf
144+
from typedpkg_ns.a.dne import dne
145145

146146
af("abc")
147147
bf(False)
@@ -151,16 +151,16 @@ af(False)
151151
bf(2)
152152
dne("abc")
153153
[out]
154-
testTypedPkgNamespaceImportAs.py:4: error: Cannot find implementation or library stub for module named "typedpkg_ns.ns.dne"
154+
testTypedPkgNamespaceImportAs.py:4: error: Cannot find implementation or library stub for module named "typedpkg_ns.a.dne"
155155
testTypedPkgNamespaceImportAs.py:4: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
156156
testTypedPkgNamespaceImportAs.py:10: error: Argument 1 has incompatible type "bool"; expected "str"
157157
testTypedPkgNamespaceImportAs.py:11: error: Argument 1 has incompatible type "int"; expected "bool"
158158

159159
[case testTypedPkgNamespaceRegImport]
160-
# pkgs: typedpkg, typedpkg_ns
160+
# pkgs: typedpkg, typedpkg_ns_a
161161
import typedpkg.pkg.aaa; af = typedpkg.pkg.aaa.af
162-
import typedpkg_ns.ns.bbb; bf = typedpkg_ns.ns.bbb.bf
163-
from typedpkg_ns.ns.dne import dne
162+
import typedpkg_ns.a.bbb; bf = typedpkg_ns.a.bbb.bf
163+
from typedpkg_ns.a.dne import dne
164164

165165
af("abc")
166166
bf(False)
@@ -171,7 +171,7 @@ bf(2)
171171
dne("abc")
172172

173173
[out]
174-
testTypedPkgNamespaceRegImport.py:4: error: Cannot find implementation or library stub for module named "typedpkg_ns.ns.dne"
174+
testTypedPkgNamespaceRegImport.py:4: error: Cannot find implementation or library stub for module named "typedpkg_ns.a.dne"
175175
testTypedPkgNamespaceRegImport.py:4: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
176176
testTypedPkgNamespaceRegImport.py:10: error: Argument 1 has incompatible type "bool"; expected "str"
177177
testTypedPkgNamespaceRegImport.py:11: error: Argument 1 has incompatible type "int"; expected "bool"
@@ -188,9 +188,36 @@ import a
188188
a.py:1: error: Unsupported operand types for + ("int" and "str")
189189

190190
[case testTypedPkgNamespaceRegFromImportTwice]
191-
# pkgs: typedpkg_ns
192-
from typedpkg_ns import ns
191+
# pkgs: typedpkg_ns_a
192+
from typedpkg_ns import a
193193
-- dummy should trigger a second iteration
194194
[file dummy.py.2]
195195
[out]
196196
[out2]
197+
198+
[case testNamespacePkgWStubs]
199+
# pkgs: typedpkg_ns_a, typedpkg_ns_b, typedpkg_ns_b-stubs
200+
import typedpkg_ns.a.bbb as a
201+
import typedpkg_ns.b.bbb as b
202+
a.bf(False)
203+
b.bf(False)
204+
a.bf(1)
205+
b.bf(1)
206+
[out]
207+
testNamespacePkgWStubs.py:3: error: Skipping analyzing "typedpkg_ns.b.bbb": found module but no type hints or library stubs
208+
testNamespacePkgWStubs.py:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
209+
testNamespacePkgWStubs.py:3: error: Skipping analyzing "typedpkg_ns.b": found module but no type hints or library stubs
210+
testNamespacePkgWStubs.py:6: error: Argument 1 to "bf" has incompatible type "int"; expected "bool"
211+
212+
[case testNamespacePkgWStubsWithNamespacePackagesFlag]
213+
# pkgs: typedpkg_ns_a, typedpkg_ns_b, typedpkg_ns_b-stubs
214+
# flags: --namespace-packages
215+
import typedpkg_ns.a.bbb as a
216+
import typedpkg_ns.b.bbb as b
217+
a.bf(False)
218+
b.bf(False)
219+
a.bf(1)
220+
b.bf(1)
221+
[out]
222+
testNamespacePkgWStubsWithNamespacePackagesFlag.py:7: error: Argument 1 to "bf" has incompatible type "int"; expected "bool"
223+
testNamespacePkgWStubsWithNamespacePackagesFlag.py:8: error: Argument 1 to "bf" has incompatible type "int"; expected "bool"

0 commit comments

Comments
 (0)