-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Expand file tree
/
Copy pathpep561.test
More file actions
310 lines (278 loc) · 11 KB
/
Copy pathpep561.test
File metadata and controls
310 lines (278 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
[case testTypedPkgNoSitePkgsIgnoredImports]
# pkgs: typedpkg
# flags: --no-site-packages
from typedpkg.sample import ex
from typedpkg import dne
a = ex([''])
reveal_type(a)
[file mypy.ini]
\[mypy]
ignore_missing_imports = True
[out]
testTypedPkgNoSitePkgsIgnoredImports.py:6: note: Revealed type is "Any"
[case testTypedPkgSimple]
# pkgs: typedpkg
from typedpkg.sample import ex
from typedpkg import dne
a = ex([''])
reveal_type(a)
[out]
testTypedPkgSimple.py:5: note: Revealed type is "tuple[str, ...]"
[case testTypedPkgSimplePackageSearchPath]
# pkgs: typedpkg
# flags: -p typedpkg.pkg
[out]
[case testTypedPkg_config_nositepackages]
# pkgs: typedpkg
from typedpkg.sample import ex
from typedpkg import dne
a = ex([''])
reveal_type(a)
[file mypy.ini]
\[mypy]
no_site_packages=True
[out]
testTypedPkg_config_nositepackages.py:2: error: Cannot find implementation or library stub for module named "typedpkg.sample"
testTypedPkg_config_nositepackages.py:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
testTypedPkg_config_nositepackages.py:3: error: Cannot find implementation or library stub for module named "typedpkg"
testTypedPkg_config_nositepackages.py:5: note: Revealed type is "Any"
[case testTypedPkg_args_nositepackages]
# pkgs: typedpkg
# flags: --no-site-packages
from typedpkg.sample import ex
from typedpkg import dne
a = ex([''])
reveal_type(a)
[out]
testTypedPkg_args_nositepackages.py:3: error: Cannot find implementation or library stub for module named "typedpkg.sample"
testTypedPkg_args_nositepackages.py:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
testTypedPkg_args_nositepackages.py:4: error: Cannot find implementation or library stub for module named "typedpkg"
testTypedPkg_args_nositepackages.py:6: note: Revealed type is "Any"
[case testTypedPkgStubs]
# pkgs: typedpkg-stubs
from typedpkg.sample import ex
from typedpkg import dne
a = ex([''])
reveal_type(a)
[out]
testTypedPkgStubs.py:3: error: Module "typedpkg" has no attribute "dne"
testTypedPkgStubs.py:5: note: Revealed type is "list[str]"
[case testStubPrecedence]
# pkgs: typedpkg, typedpkg-stubs
from typedpkg.sample import ex
from typedpkg import dne
a = ex([''])
reveal_type(a)
[out]
testStubPrecedence.py:5: note: Revealed type is "list[str]"
[case testTypedPkgSimpleEditable]
# pkgs: typedpkg; editable
from typedpkg.sample import ex
from typedpkg import dne
a = ex([''])
reveal_type(a)
[out]
testTypedPkgSimpleEditable.py:5: note: Revealed type is "tuple[str, ...]"
[case testTypedPkgNamespaceImportFrom]
# pkgs: typedpkg, typedpkg_ns_a
from typedpkg.pkg.aaa import af
from typedpkg_ns.a.bbb import bf
from typedpkg_ns.a.dne import dne
af("abc")
bf(False)
dne(123)
af(False)
bf(2)
dne("abc")
[out]
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_a
import typedpkg.pkg.aaa as nm; af = nm.af
import typedpkg_ns.a.bbb as am; bf = am.bf
from typedpkg_ns.a.dne import dne
af("abc")
bf(False)
dne(123)
af(False)
bf(2)
dne("abc")
[out]
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_a
import typedpkg.pkg.aaa; af = typedpkg.pkg.aaa.af
import typedpkg_ns.a.bbb; bf = typedpkg_ns.a.bbb.bf
from typedpkg_ns.a.dne import dne
af("abc")
bf(False)
dne(123)
af(False)
bf(2)
dne("abc")
[out]
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"
-- This is really testing the test framework to make sure incremental works
[case testPep561TestIncremental]
# pkgs: typedpkg
import a
[file a.py]
[file a.py.2]
1 + 'no'
[out]
[out2]
a.py:1: error: Unsupported operand types for + ("int" and "str")
[case testTypedPkgNamespaceRegFromImportTwice]
# 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
# flags: --no-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)
import typedpkg_ns.whatever as c # type: ignore[import-untyped]
[out]
testNamespacePkgWStubs.py:4: error: Skipping analyzing "typedpkg_ns.b.bbb": module is installed, but missing library stubs or py.typed marker
testNamespacePkgWStubs.py:4: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
testNamespacePkgWStubs.py:4: error: Skipping analyzing "typedpkg_ns.b": module is installed, but missing library stubs or py.typed marker
testNamespacePkgWStubs.py:7: 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"
[case testMissingPytypedFlag]
# pkgs: typedpkg_ns_b
# flags: --namespace-packages --follow-untyped-imports
import typedpkg_ns.b.bbb as b
b.bf("foo", "bar")
[out]
testMissingPytypedFlag.py:4: error: Too many arguments for "bf"
[case testTypedPkgNamespaceRegFromImportTwiceMissing]
# pkgs: typedpkg_ns_a
from typedpkg_ns import does_not_exist # type: ignore
from typedpkg_ns import a
-- dummy should trigger a second iteration
[file dummy.py.2]
[out]
[out2]
[case testTypedPkgNamespaceRegFromImportTwiceMissing2]
# pkgs: typedpkg_ns_a
from typedpkg_ns import does_not_exist # type: ignore
from typedpkg_ns.a.bbb import bf
-- dummy should trigger a second iteration
[file dummy.py.2]
[out]
[out2]
[case testTypedNamespaceSubpackage]
# pkgs: typedpkg_ns_nested
import our
[file our/__init__.py]
import our.bar
import our.foo
[file our/bar.py]
from typedpkg_ns.b import Something
[file our/foo.py]
import typedpkg_ns.a
[file dummy.py.2]
[out]
our/bar.py:1: error: Skipping analyzing "typedpkg_ns.b": module is installed, but missing library stubs or py.typed marker
our/bar.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
[out2]
our/bar.py:1: error: Skipping analyzing "typedpkg_ns.b": module is installed, but missing library stubs or py.typed marker
our/bar.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
[case testPartiallyTypedNamespacePackageNoCrash]
# pkgs: typedpkg_ns_nested
import a
[file a.py]
import m1
import m2
[file a.py.2]
import m1
[file m1.py]
import typedpkg_ns.b # type: ignore
[file m2.py]
import typedpkg_ns.a
[out]
[out2]
[case testUntypedParentWithTypedSubDoesNotBreakReExports]
# pkgs: untypedpkg_w_typed_sub
# Regression: untyped parent with a typed subpackage. The parent gets a
# synthetic __getattr__ so unresolved attrs return Any (no spurious
# attr-defined), but real submodules still win in attribute lookup so
# dotted access through the parent stays precisely typed.
import other
from untypedpkg_w_typed_sub import re_exported # type: ignore[import-untyped]
reveal_type(re_exported)
[file other.py]
import untypedpkg_w_typed_sub.typed_sub # type: ignore[import-untyped]
import untypedpkg_w_typed_sub.typed_sub as ts # type: ignore[import-untyped]
from untypedpkg_w_typed_sub import typed_sub # type: ignore[import-untyped]
from untypedpkg_w_typed_sub.typed_sub import EXAMPLE_CONST # type: ignore[import-untyped]
reveal_type(untypedpkg_w_typed_sub.typed_sub.EXAMPLE_CONST)
reveal_type(ts.EXAMPLE_CONST)
reveal_type(typed_sub.EXAMPLE_CONST)
reveal_type(EXAMPLE_CONST)
[out]
other.py:5: note: Revealed type is "int"
other.py:6: note: Revealed type is "int"
other.py:7: note: Revealed type is "int"
other.py:8: note: Revealed type is "int"
testUntypedParentWithTypedSubDoesNotBreakReExports.py:8: note: Revealed type is "Any"
[case testUntypedParentWithTypedSubFollowUntypedImports]
# pkgs: untypedpkg_w_typed_sub
# flags: --follow-untyped-imports
# When the user opts into precise untyped-import analysis, mypy parses the
# parent's __init__.py for real -- so the re-export gets its precise type
# (not Any), and unknown attributes correctly raise attr-defined. The
# synthetic __getattr__ fix stays dormant in this mode.
import untypedpkg_w_typed_sub
import untypedpkg_w_typed_sub.typed_sub
from untypedpkg_w_typed_sub import re_exported
reveal_type(re_exported)
reveal_type(untypedpkg_w_typed_sub.typed_sub.EXAMPLE_CONST)
untypedpkg_w_typed_sub.nonexistent
[out]
testUntypedParentWithTypedSubFollowUntypedImports.py:10: note: Revealed type is "def () -> int"
testUntypedParentWithTypedSubFollowUntypedImports.py:11: note: Revealed type is "int"
testUntypedParentWithTypedSubFollowUntypedImports.py:12: error: Module has no attribute "nonexistent"
[case testUntypedParentWithTypedSubGetattrIsHidden]
# pkgs: untypedpkg_w_typed_sub
# The synthetic __getattr__ must not leak as a user-visible attribute or
# satisfy `from pkg import __getattr__`. Direct access to `pkg.__getattr__`
# should fall through to `types.ModuleType.__getattr__` -- the same answer
# a plain untyped module would give.
import untypedpkg_w_typed_sub.typed_sub # type: ignore[import-untyped]
import untypedpkg_w_typed_sub # type: ignore[import-untyped]
reveal_type(untypedpkg_w_typed_sub.__getattr__)
from untypedpkg_w_typed_sub import __getattr__ as g # type: ignore[import-untyped]
reveal_type(g)
[out]
testUntypedParentWithTypedSubGetattrIsHidden.py:8: note: Revealed type is "def (str) -> Any"
testUntypedParentWithTypedSubGetattrIsHidden.py:9: error: Module "untypedpkg_w_typed_sub" does not explicitly export attribute "__getattr__"
testUntypedParentWithTypedSubGetattrIsHidden.py:9: note: Error code "attr-defined" not covered by "type: ignore[import-untyped]" comment
testUntypedParentWithTypedSubGetattrIsHidden.py:10: note: Revealed type is "Any"