Skip to content

Commit eb495ff

Browse files
sobolevnsrittauAlexWaygood
authored
Update mypy to 1.16.0 (#14194)
Co-authored-by: Sebastian Rittau <srittau@rittau.biz> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
1 parent 09b6802 commit eb495ff

File tree

13 files changed

+72
-78
lines changed

13 files changed

+72
-78
lines changed

requirements-tests.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Type checkers that we test our stubs against. These should always
22
# be pinned to a specific version to make failure reproducible.
3-
mypy==1.15.0
3+
mypy==1.16.0
44
pyright==1.1.400
55
# pytype can be installed on Windows, but requires building wheels, let's not do that on the CI
66
pytype==2024.10.11; platform_system != "Windows" and python_version >= "3.10" and python_version < "3.13"

stdlib/@tests/stubtest_allowlists/common.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ _?ast.stmt.__init__
210210

211211
_ast.ImportFrom.level # None on the class, but never None on instances
212212

213+
argparse.Namespace.__setattr__ # should allow setting any attribute
214+
213215
ast.ImportFrom.level # None on the class, but never None on instances
214216
ast.NodeVisitor.visit_\w+ # Methods are discovered dynamically, see #3796
215217
_?asyncio.Future.__init__ # Usually initialized from c object
@@ -272,7 +274,9 @@ _?ctypes.Array._length_ # _length_ is abstract, https://github.com/python/types
272274
_?ctypes.Array.raw # exists but stubtest can't see it; only available if _CT == c_char
273275
ctypes.CDLL._FuncPtr # None at class level but initialized in __init__ to this value
274276
_?ctypes.Structure.__getattr__ # doesn't exist, but makes things easy if we pretend it does
277+
_?ctypes.Structure.__setattr__ # doesn't exist, but makes things easy if we pretend it does
275278
_?ctypes.Union.__getattr__ # doesn't exist, but makes things easy if we pretend it does
279+
_?ctypes.Union.__setattr__ # doesn't exist, but makes things easy if we pretend it does
276280

277281
# Iterable classes that don't define __iter__ at runtime (usually iterable via __getitem__)
278282
# These would ideally be special-cased by type checkers; see https://github.com/python/mypy/issues/2220
@@ -323,6 +327,8 @@ inspect.Signature.__init__
323327
inspect.Parameter.empty # set as private marker _empty
324328
inspect.Signature.empty # set as private marker _empty
325329

330+
logging.LogRecord.__setattr__ # doesn't exist, but makes things easy if we pretend it does
331+
326332
# Iterable classes that don't define __iter__ at runtime (usually iterable via __getitem__)
327333
# These would ideally be special-cased by type checkers; see https://github.com/python/mypy/issues/2220
328334
mmap.mmap.__iter__
@@ -380,7 +386,9 @@ multiprocessing.synchronize.SemLock.acquire
380386
multiprocessing.synchronize.SemLock.release
381387

382388
numbers.Number.__hash__ # typeshed marks this as abstract but code just sets this as None
389+
383390
optparse.Values.__getattr__ # Some attributes are set in __init__ using setattr
391+
optparse.Values.__setattr__ # doesn't exist, but makes things easy if we pretend it does
384392

385393
os._wrap_close.read # Methods that come from __getattr__() at runtime
386394
os._wrap_close.readable # Methods that come from __getattr__() at runtime

stdlib/@tests/stubtest_allowlists/py312.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ zoneinfo.ZoneInfo.from_file # Pos-only parameters had different "names" in diff
1313
typing_extensions.TypeAliasType.__parameters__
1414
typing_extensions.TypeAliasType.__value__
1515

16+
# Types that require `__setattr__` and `__delattr__` for typing purposes:
17+
types.SimpleNamespace.__setattr__
18+
types.SimpleNamespace.__delattr__
19+
1620

1721
# ====================================
1822
# Pre-existing errors from Python 3.11

stdlib/@tests/stubtest_allowlists/py313.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ zoneinfo.ZoneInfo.from_file # Pos-only parameters had different "names" in diff
1818
typing_extensions.TypeAliasType.__parameters__
1919
typing_extensions.TypeAliasType.__value__
2020

21+
# Types that require `__setattr__` and `__delattr__` for typing purposes:
22+
types.SimpleNamespace.__setattr__
23+
types.SimpleNamespace.__delattr__
24+
2125

2226
# =======
2327
# >= 3.11

stdlib/@tests/stubtest_allowlists/py314.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ functools.partialmethod.__new__
5555

5656
zoneinfo.ZoneInfo.from_file # Pos-only parameters had different "names" in different Python versions
5757

58+
# Types that require `__setattr__` and `__delattr__` for typing purposes:
59+
types.SimpleNamespace.__setattr__
60+
types.SimpleNamespace.__delattr__
61+
5862

5963
# =======
6064
# >= 3.11
@@ -101,10 +105,6 @@ typing(_extensions)?\.IO\.writelines
101105
# Allowlist entries that cannot or should not be fixed; >= 3.14
102106
# =============================================================
103107

104-
# Internal annotations machinery
105-
.*\.__annotate_func__
106-
.*\.__annotations_cache__
107-
108108
# Undocumented private attributes
109109
.*\.ForwardRef\.__arg__
110110
.*\.ForwardRef\.__ast_node__

stubs/WTForms/@tests/stubtest_allowlist.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ wtforms.fields.core.Field.__get__
99
# to let mypy know that arbitrary attribute access is possible
1010
wtforms.meta.DefaultMeta.__getattr__
1111

12+
# Should allow setting and deleting any attribute
13+
wtforms.Flags.__delattr__
14+
wtforms.Flags.__setattr__
15+
wtforms.fields.Flags.__delattr__
16+
wtforms.fields.Flags.__setattr__
17+
wtforms.fields.core.Flags.__delattr__
18+
wtforms.fields.core.Flags.__setattr__
19+
1220
# Error: variable differs from runtime
1321
# ======================
1422
# _unbound_fields has some weird semantics: due to the metaclass it

stubs/openpyxl/@tests/test_cases/check_base_descriptors.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -177,27 +177,27 @@ class WithDescriptorsStrict(Strict):
177177
assert_type(with_descriptors.match_pattern_bytes, ReadableBuffer)
178178
assert_type(with_descriptors.match_pattern_bytes_none, Union[ReadableBuffer, None])
179179

180-
assert_type(with_descriptors.convertible_not_none, int) # type: ignore[assert-type] # False-positive in mypy
180+
assert_type(with_descriptors.convertible_not_none, int)
181181
assert_type(with_descriptors.convertible_none, Union[int, None])
182182

183-
assert_type(with_descriptors.minmax_float, float) # type: ignore[assert-type] # False-positive in mypy
183+
assert_type(with_descriptors.minmax_float, float)
184184
assert_type(with_descriptors.minmax_float_none, Union[float, None])
185-
assert_type(with_descriptors.minmax_int, int) # type: ignore[assert-type] # False-positive in mypy
185+
assert_type(with_descriptors.minmax_int, int)
186186
assert_type(with_descriptors.minmax_int_none, Union[int, None])
187187

188-
assert_type(with_descriptors.bool_not_none, bool) # type: ignore[assert-type] # False-positive in mypy
188+
assert_type(with_descriptors.bool_not_none, bool)
189189
assert_type(with_descriptors.bool_none, Union[bool, None])
190190

191-
assert_type(with_descriptors.datetime_not_none, datetime) # type: ignore[assert-type] # False-positive in mypy
191+
assert_type(with_descriptors.datetime_not_none, datetime)
192192
assert_type(with_descriptors.datetime_none, Union[datetime, None])
193193

194-
assert_type(with_descriptors.string_not_none, str) # type: ignore[assert-type] # False-positive in mypy
194+
assert_type(with_descriptors.string_not_none, str)
195195
assert_type(with_descriptors.string_none, Union[str, None])
196196

197-
assert_type(with_descriptors.float_not_none, float) # type: ignore[assert-type] # False-positive in mypy
197+
assert_type(with_descriptors.float_not_none, float)
198198
assert_type(with_descriptors.float_none, Union[float, None])
199199

200-
assert_type(with_descriptors.integer_not_none, int) # type: ignore[assert-type] # False-positive in mypy
200+
assert_type(with_descriptors.integer_not_none, int)
201201
assert_type(with_descriptors.integer_none, Union[int, None])
202202

203203

@@ -289,8 +289,8 @@ class WithDescriptorsStrict(Strict):
289289

290290
with_descriptors.convertible_not_none = 0
291291
with_descriptors.convertible_not_none = "0"
292-
with_descriptors.convertible_not_none = None # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
293-
with_descriptors.convertible_not_none = object() # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
292+
with_descriptors.convertible_not_none = None # type: ignore
293+
with_descriptors.convertible_not_none = object() # type: ignore
294294

295295
with_descriptors.convertible_none = 0
296296
with_descriptors.convertible_none = "0"
@@ -301,7 +301,7 @@ class WithDescriptorsStrict(Strict):
301301
with_descriptors.minmax_float = 0
302302
with_descriptors.minmax_float = "0"
303303
with_descriptors.minmax_float = 0.0
304-
with_descriptors.minmax_float = None # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
304+
with_descriptors.minmax_float = None # type: ignore
305305
with_descriptors.minmax_float = object() # type: ignore
306306

307307
with_descriptors.minmax_float_none = 0
@@ -313,7 +313,7 @@ class WithDescriptorsStrict(Strict):
313313
with_descriptors.minmax_int = 0
314314
with_descriptors.minmax_int = "0"
315315
with_descriptors.minmax_int = 0.0
316-
with_descriptors.minmax_int = None # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
316+
with_descriptors.minmax_int = None # type: ignore
317317
with_descriptors.minmax_int = object() # type: ignore
318318

319319
with_descriptors.minmax_int_none = 0
@@ -354,7 +354,7 @@ class WithDescriptorsStrict(Strict):
354354

355355

356356
with_descriptors.string_not_none = ""
357-
with_descriptors.string_not_none = None # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
357+
with_descriptors.string_not_none = None # type: ignore
358358
with_descriptors.string_not_none = 0 # type: ignore
359359

360360
with_descriptors.string_none = ""
@@ -366,8 +366,8 @@ class WithDescriptorsStrict(Strict):
366366
with_descriptors.float_not_none = 0.0
367367
with_descriptors.float_not_none = "0"
368368
with_descriptors.float_not_none = b"0"
369-
with_descriptors.float_not_none = None # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
370-
with_descriptors.float_not_none = object() # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
369+
with_descriptors.float_not_none = None # type: ignore
370+
with_descriptors.float_not_none = object() # type: ignore
371371

372372
with_descriptors.float_none = 0
373373
with_descriptors.float_none = 0.0
@@ -381,8 +381,8 @@ class WithDescriptorsStrict(Strict):
381381
with_descriptors.integer_not_none = 0.0
382382
with_descriptors.integer_not_none = "0"
383383
with_descriptors.integer_not_none = b"0"
384-
with_descriptors.integer_not_none = None # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
385-
with_descriptors.integer_not_none = object() # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
384+
with_descriptors.integer_not_none = None # type: ignore
385+
with_descriptors.integer_not_none = object() # type: ignore
386386

387387
with_descriptors.integer_none = 0
388388
with_descriptors.integer_none = 0.0

stubs/openpyxl/@tests/test_cases/check_nested_descriptors.py

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -167,19 +167,19 @@ class WithDescriptorsStrict(Strict):
167167
assert_type(with_descriptors.minmax_int, int)
168168
assert_type(with_descriptors.minmax_int_none, Union[int, None])
169169

170-
assert_type(with_descriptors.bool_not_none, bool) # type: ignore[assert-type] # False-positive in mypy
170+
assert_type(with_descriptors.bool_not_none, bool)
171171
assert_type(with_descriptors.bool_none, Union[bool, None])
172172

173173
assert_type(with_descriptors.emptytag_not_none, bool)
174174
assert_type(with_descriptors.emptytag_none, Union[bool, None])
175175

176-
assert_type(with_descriptors.string_not_none, str) # type: ignore[assert-type] # False-positive in mypy
176+
assert_type(with_descriptors.string_not_none, str)
177177
assert_type(with_descriptors.string_none, Union[str, None])
178178

179-
assert_type(with_descriptors.float_not_none, float) # type: ignore[assert-type] # False-positive in mypy
179+
assert_type(with_descriptors.float_not_none, float)
180180
assert_type(with_descriptors.float_none, Union[float, None])
181181

182-
assert_type(with_descriptors.integer_not_none, int) # type: ignore[assert-type] # False-positive in mypy
182+
assert_type(with_descriptors.integer_not_none, int)
183183
assert_type(with_descriptors.integer_none, Union[int, None])
184184

185185

@@ -264,15 +264,11 @@ class WithDescriptorsStrict(Strict):
264264

265265
with_descriptors.convertible_not_none = 0
266266
with_descriptors.convertible_not_none = "0"
267-
with_descriptors.convertible_not_none = None # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
268-
with_descriptors.convertible_not_none = object() # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
267+
with_descriptors.convertible_not_none = None # type: ignore
268+
with_descriptors.convertible_not_none = object() # type: ignore
269269
with_descriptors.convertible_not_none = cast(_HasTagAndGet[str], _)
270-
with_descriptors.convertible_not_none = cast( # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
271-
_HasTagAndGet[None], _
272-
)
273-
with_descriptors.convertible_not_none = cast( # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
274-
_HasTagAndGet[object], _
275-
)
270+
with_descriptors.convertible_not_none = cast(_HasTagAndGet[None], _) # type: ignore
271+
with_descriptors.convertible_not_none = cast(_HasTagAndGet[object], _) # type: ignore
276272

277273
with_descriptors.convertible_none = 0
278274
with_descriptors.convertible_none = "0"
@@ -426,15 +422,11 @@ class WithDescriptorsStrict(Strict):
426422
with_descriptors.float_not_none = 0.0
427423
with_descriptors.float_not_none = "0"
428424
with_descriptors.float_not_none = b"0"
429-
with_descriptors.float_not_none = None # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
430-
with_descriptors.float_not_none = object() # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
425+
with_descriptors.float_not_none = None # type: ignore
426+
with_descriptors.float_not_none = object() # type: ignore
431427
with_descriptors.float_not_none = cast(_HasTagAndGet[float], _)
432-
with_descriptors.float_not_none = cast( # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
433-
_HasTagAndGet[None], _
434-
)
435-
with_descriptors.float_not_none = cast( # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
436-
_HasTagAndGet[object], _
437-
)
428+
with_descriptors.float_not_none = cast(_HasTagAndGet[None], _) # type: ignore
429+
with_descriptors.float_not_none = cast(_HasTagAndGet[object], _) # type: ignore
438430

439431
with_descriptors.float_none = 0
440432
with_descriptors.float_none = 0.0
@@ -451,15 +443,11 @@ class WithDescriptorsStrict(Strict):
451443
with_descriptors.integer_not_none = 0.0
452444
with_descriptors.integer_not_none = "0"
453445
with_descriptors.integer_not_none = b"0"
454-
with_descriptors.integer_not_none = None # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
455-
with_descriptors.integer_not_none = object() # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
446+
with_descriptors.integer_not_none = None # type: ignore
447+
with_descriptors.integer_not_none = object() # type: ignore
456448
with_descriptors.integer_not_none = cast(_HasTagAndGet[int], _)
457-
with_descriptors.integer_not_none = cast( # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
458-
_HasTagAndGet[None], _
459-
)
460-
with_descriptors.integer_not_none = cast( # pyright: ignore[reportAttributeAccessIssue] # false negative in mypy
461-
_HasTagAndGet[object], _
462-
)
449+
with_descriptors.integer_not_none = cast(_HasTagAndGet[None], _) # type: ignore
450+
with_descriptors.integer_not_none = cast(_HasTagAndGet[object], _) # type: ignore
463451

464452
with_descriptors.integer_none = 0
465453
with_descriptors.integer_none = 0.0

stubs/passlib/@tests/stubtest_allowlist.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ passlib.utils.handlers.HasRounds.rounds
3838
# Errors in `__all__` at runtime:
3939
# TODO: change after https://github.com/python/mypy/pull/14217 is released
4040
passlib.handlers.oracle.__all__
41-
passlib.handlers.oracle.oracle11g
42-
passlib.handlers.oracle.oracle10g
4341
passlib.handlers.mysql.__all__
44-
passlib.handlers.mysql.mysq41
4542

4643
# Compat tools are ignored:
4744
passlib.utils.compat.*

stubs/python-xlib/@tests/stubtest_allowlist.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ Xlib.protocol.rq.DictWrapper.__lt__
1212
Xlib.protocol.rq.Event.__gt__
1313
Xlib.protocol.rq.Event.__lt__
1414

15+
# should allow setting any attribute
16+
Xlib.protocol.rq.GetAttrData.__setattr__
17+
1518
# Can be None or str once instantiated
1619
Xlib.protocol.rq.*.structcode
1720
# Should only ever be str once instantiated

0 commit comments

Comments
 (0)