Skip to content

Commit 48e76e8

Browse files
authored
Bump mypy to 0.981 (#8796)
1 parent 9abe56a commit 48e76e8

File tree

29 files changed

+23
-185
lines changed

29 files changed

+23
-185
lines changed

Diff for: requirements-tests.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ flake8-bugbear==22.7.1 # must match .pre-commit-config.yaml
55
flake8-noqa==1.2.9 # must match .pre-commit-config.yaml
66
flake8-pyi==22.8.2 # must match .pre-commit-config.yaml
77
isort==5.10.1 # must match .pre-commit-config.yaml
8-
mypy==0.971
8+
mypy==0.981
99
packaging==21.3
1010
pycln==2.1.1 # must match .pre-commit-config.yaml
1111
pyyaml==6.0

Diff for: stdlib/builtins.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -1952,7 +1952,7 @@ if sys.version_info >= (3, 11):
19521952
@overload
19531953
def subgroup(self: Self, __condition: Callable[[_BaseExceptionT_co], bool]) -> Self | None: ...
19541954
@overload
1955-
def split(
1955+
def split( # type: ignore[misc] # complaints about overlapping overloads
19561956
self: Self, __condition: type[_BaseExceptionT] | tuple[type[_BaseExceptionT], ...]
19571957
) -> tuple[BaseExceptionGroup[_BaseExceptionT] | None, Self | None]: ...
19581958
@overload
@@ -1972,7 +1972,7 @@ if sys.version_info >= (3, 11):
19721972
@overload
19731973
def subgroup(self: Self, __condition: Callable[[_ExceptionT_co], bool]) -> Self | None: ...
19741974
@overload # type: ignore[override]
1975-
def split(
1975+
def split( # type: ignore[misc] # complaints about overlapping overloads
19761976
self: Self, __condition: type[_ExceptionT] | tuple[type[_ExceptionT], ...]
19771977
) -> tuple[ExceptionGroup[_ExceptionT] | None, Self | None]: ...
19781978
@overload

Diff for: stdlib/importlib/metadata/__init__.pyi

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class _EntryPointBase(NamedTuple):
4141

4242
class EntryPoint(_EntryPointBase):
4343
pattern: ClassVar[Pattern[str]]
44+
if sys.version_info >= (3, 11):
45+
def __init__(self, name: str, value: str, group: str) -> None: ...
46+
4447
def load(self) -> Any: ... # Callable[[], Any] or an importable module
4548
@property
4649
def extras(self) -> list[str]: ...

Diff for: stubs/PyYAML/@tests/stubtest_allowlist.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
# yaml._yaml is for backwards compatibility so none of it matters anyway
2-
yaml._yaml.CEmitter.__pyx_vtable__
3-
yaml._yaml.CParser.__pyx_vtable__
42
yaml._yaml.__test__

Diff for: stubs/SQLAlchemy/@tests/stubtest_allowlist.txt

-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ sqlalchemy.ext.declarative.as_declarative
1414
sqlalchemy.orm.collections.InstrumentedList.*
1515
sqlalchemy.orm.collections.InstrumentedSet.*
1616
sqlalchemy.orm.collections.MappedCollection.*
17-
sqlalchemy.util.OrderedDict.get
1817
sqlalchemy.util.StringIO.*
19-
sqlalchemy.util.byte_buffer.*
20-
sqlalchemy.util.column_dict.get
2118

2219
# method arguments starting with double underscores in the implementation
2320
sqlalchemy.testing.resolve_lambda

Diff for: stubs/cffi/@tests/stubtest_allowlist.txt

-6
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ cffi.(api.)?FFI.buffer
99
# Exists at runtime, but missing from stubs
1010
cffi.vengine_cpy.__warningregistry__
1111

12-
# Alias to io.StringIO, which has the same allowlist
13-
cffi.recompiler.NativeIO.seek
14-
cffi.recompiler.NativeIO.truncate
15-
cffi.verifier.NativeIO.seek
16-
cffi.verifier.NativeIO.truncate
17-
1812
# Unnecessary re-exports
1913
cffi.cparser.COMMON_TYPES
2014
cffi.verifier.__version_verifier_modules__

Diff for: stubs/hdbcli/@tests/stubtest_allowlist.txt

-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,3 @@ hdbcli.dbapi.Error.errorcode
22
hdbcli.dbapi.Error.errortext
33
hdbcli.dbapi.Warning.errorcode
44
hdbcli.dbapi.Warning.errortext
5-
# Similar issues to builtins.memoryview
6-
hdbcli.dbapi.BINARY.__iter__
7-
hdbcli.dbapi.BINARY.cast
8-
hdbcli.dbapi.BINARY.__contains__

Diff for: stubs/html5lib/@tests/stubtest_allowlist.txt

-3
This file was deleted.

Diff for: stubs/html5lib/html5lib/_inputstream.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class HTMLBinaryInputStream(HTMLUnicodeInputStream):
7272
def detectEncodingMeta(self): ...
7373

7474
class EncodingBytes(bytes):
75-
def __new__(cls, value): ...
75+
def __new__(self, value): ...
7676
def __init__(self, value) -> None: ...
7777
def __iter__(self): ...
7878
def __next__(self): ...

Diff for: stubs/jsonschema/@tests/stubtest_allowlist.txt

-2
This file was deleted.

Diff for: stubs/keyboard/@tests/stubtest_allowlist.txt

+1-10
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,5 @@ keyboard._keyboard_event.KeyboardEvent.scan_code
44
# Defaults don't align with possible values
55
keyboard.mouse.on_button
66
keyboard.mouse.wait
7-
# Private modules and tests
7+
# TODO: Should this be allowlisted?
88
keyboard.__main__
9-
keyboard._darwinkeyboard
10-
keyboard._darwinmouse
11-
keyboard._keyboard_tests
12-
keyboard._mouse_tests
13-
keyboard._nixcommon
14-
keyboard._nixkeyboard
15-
keyboard._nixmouse
16-
keyboard._winkeyboard
17-
keyboard._winmouse

Diff for: stubs/pyinstaller/@tests/stubtest_allowlist.txt

-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,3 @@ PyInstaller.utils.osx
3636
PyInstaller.utils.run_tests
3737
PyInstaller.utils.tests
3838
PyInstaller.utils.win32.*
39-
# Explicitly private implementation details
40-
PyInstaller\._.*
41-
PyInstaller.isolated._child
42-
PyInstaller.utils._gitrevision

Diff for: stubs/redis/@tests/stubtest_allowlist.txt

-17
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,6 @@
11
redis.client.Pipeline.transaction # instance attribute has same name as superclass method
22
redis.ocsp # requires cryptography to be installed
33

4-
# TypeAlias-related problems
5-
redis.asyncio.client.CommandStackT
6-
redis.asyncio.client.CommandT
7-
redis.asyncio.client.PubSubHandler
8-
redis.asyncio.connection.ExceptionMappingT
9-
10-
# Protocol-related problems
11-
redis.asyncio.client.AsyncPubsubWorkerExceptionHandler.__init__
12-
redis.asyncio.client.AsyncResponseCallbackProtocol.__init__
13-
redis.asyncio.client.PubsubWorkerExceptionHandler.__init__
14-
redis.asyncio.client.ResponseCallbackProtocol.__init__
15-
redis.asyncio.connection.AsyncConnectCallbackProtocol.__init__
16-
redis.asyncio.connection.ConnectCallbackProtocol.__init__
17-
redis.typing.CommandsProtocol.__init__
18-
194
# async def mismatch problems
205
redis.asyncio.client.Pipeline.command_info
216
redis.asyncio.client.Pipeline.debug_segfault
@@ -25,8 +10,6 @@ redis.asyncio.client.Pipeline.script_debug
2510
redis.asyncio.client.Pipeline.shutdown
2611

2712
# unclear problems
28-
redis.Sentinel.master_for
29-
redis.Sentinel.slave_for
3013
redis.asyncio.Sentinel.master_for
3114
redis.asyncio.Sentinel.slave_for
3215
redis.asyncio.sentinel.Sentinel.master_for

Diff for: stubs/six/@tests/stubtest_allowlist.txt

-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ six.viewkeys
2121
six.viewvalues
2222

2323
# Unclear problems
24-
six.Iterator.__init__
2524
six.callable

Diff for: stubs/tqdm/tqdm/contrib/logging.pyi

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ def logging_redirect_tqdm(
1313
) -> _GeneratorContextManager[None]: ...
1414

1515
# TODO type *args, **kwargs here more precisely
16+
# The type ignore is because mypy complains that the second overload will never be matched
17+
# (I'm not sure that's true)
1618
@overload
1719
def tqdm_logging_redirect(*args, tqdm_class: Callable[..., _TqdmT], **kwargs) -> _GeneratorContextManager[_TqdmT]: ...
1820
@overload
19-
def tqdm_logging_redirect(*args, **kwargs) -> _GeneratorContextManager[std_tqdm[Incomplete]]: ...
21+
def tqdm_logging_redirect(*args, **kwargs) -> _GeneratorContextManager[std_tqdm[Incomplete]]: ... # type: ignore[misc]

Diff for: stubs/urllib3/@tests/stubtest_allowlist.txt

-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
1-
# TODO: remove ResponseCls ignore when https://github.com/python/mypy/issues/13316 is closed
2-
urllib3.HTTPConnectionPool.ResponseCls
3-
urllib3.HTTPConnectionPool.__init__
4-
urllib3.HTTPConnectionPool.urlopen
5-
urllib3.HTTPSConnectionPool.__init__
61
urllib3.NullHandler
7-
urllib3.PoolManager.connection_from_host
8-
urllib3.PoolManager.connection_from_url
9-
urllib3.PoolManager.urlopen
10-
urllib3.ProxyManager.__init__
11-
urllib3.ProxyManager.connection_from_host
12-
urllib3.ProxyManager.urlopen
132
urllib3._collections.HTTPHeaderDict.from_httplib
143
urllib3._collections.HTTPHeaderDict.getlist
154
urllib3._collections.RLock
@@ -18,14 +7,11 @@ urllib3.connection.HTTPSConnection.__init__
187
urllib3.connection.VerifiedHTTPSConnection.__init__
198
urllib3.connection.VerifiedHTTPSConnection.set_cert
209
urllib3.connectionpool.ConnectionError
21-
urllib3.connectionpool.HTTPConnection.request
2210
# TODO: remove ResponseCls ignore when https://github.com/python/mypy/issues/13316 is closed
2311
urllib3.connectionpool.HTTPConnectionPool.ResponseCls
2412
urllib3.connectionpool.HTTPConnectionPool.__init__
2513
urllib3.connectionpool.HTTPConnectionPool.urlopen
26-
urllib3.connectionpool.HTTPSConnection.__init__
2714
urllib3.connectionpool.HTTPSConnectionPool.__init__
28-
urllib3.connectionpool.RequestMethods.request_encode_url
2915
urllib3.connectionpool.VerifiedHTTPSConnection.__init__
3016
urllib3.connectionpool.VerifiedHTTPSConnection.set_cert
3117
urllib3.packages.ssl_match_hostname

Diff for: stubs/xxhash/@tests/stubtest_allowlist.txt

-1
This file was deleted.

Diff for: tests/mypy_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from io import StringIO
1414
from itertools import product
1515
from pathlib import Path
16-
from typing import TYPE_CHECKING, NamedTuple
16+
from typing import TYPE_CHECKING, Any, NamedTuple
1717

1818
if TYPE_CHECKING:
1919
from _typeshed import StrPath
@@ -157,7 +157,7 @@ def add_files(files: list[Path], seen: set[str], module: Path, args: TestConfig)
157157

158158
class MypyDistConf(NamedTuple):
159159
module_name: str
160-
values: dict
160+
values: dict[str, dict[str, Any]]
161161

162162

163163
# The configuration section in the metadata file looks like the following, with multiple module sections possible

Diff for: tests/regr_test.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ def test_testcase_directory(package: PackageInfo, version: str, platform: str) -
130130
os.mkdir(new_typeshed)
131131
shutil.copytree(Path("stdlib"), new_typeshed / "stdlib")
132132
requirements = get_recursive_requirements(package_name)
133-
for requirement in requirements:
133+
# mypy refuses to consider a directory a "valid typeshed directory"
134+
# unless there's a stubs/mypy-extensions path inside it,
135+
# so add that to the list of stubs to copy over to the new directory
136+
for requirement in requirements + ["mypy-extensions"]:
134137
shutil.copytree(Path("stubs", requirement), new_typeshed / "stubs" / requirement)
135138
env_vars["MYPYPATH"] = os.pathsep.join(map(str, new_typeshed.glob("stubs/*")))
136139
flags.extend(["--custom-typeshed-dir", str(td_path / "typeshed")])

Diff for: tests/stubtest_allowlists/darwin.txt

-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ _ctypes.dlopen
3535
_ctypes.dlsym
3636

3737
posix.NGROUPS_MAX
38-
posix.error.characters_written
39-
resource.error.characters_written
4038
select.POLLRDHUP
4139
webbrowser.MacOSX.__init__
4240

Diff for: tests/stubtest_allowlists/linux.txt

-4
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ winsound
4444
# multiprocessing.popen_spawn_win32 exists on Linux but fail to import
4545
multiprocessing.popen_spawn_win32
4646

47-
# Aliases for OSError
48-
posix.error.characters_written
49-
resource.error.characters_written
50-
5147
# Platform differences that cannot be captured by the type system
5248
fcntl.I_[A-Z0-9_]+
5349
os.SCHED_[A-Z_]+

Diff for: tests/stubtest_allowlists/py310.txt

+1-16
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ fractions.Fraction.__new__ # overload is too complicated for stubtest to resolv
1717
gettext.install
1818
gettext.translation
1919
hmac.new # Stub is a white lie; see comments in the stub
20-
importlib.metadata._meta.SimplePath.__div__ # See comments
21-
importlib.metadata._meta.SimplePath.__truediv__ # See comments
20+
importlib.metadata._meta.SimplePath.__truediv__ # See comments in the stub
2221
ipaddress.IPv4Interface.hostmask
2322
ipaddress.IPv6Interface.hostmask
2423
ipaddress._BaseNetwork.broadcast_address
@@ -73,7 +72,6 @@ _csv.Writer
7372
asynchat.__warningregistry__ # Removal planned for 3.12, can add if someone needs this
7473
bdb.Breakpoint.clearBreakpoints
7574
distutils.util.get_host_platform
76-
functools.partial.__vectorcalloffset__ # undocumented implementation detail
7775
inspect.Signature.from_builtin # Removed in 3.11, can add if someone needs this
7876
inspect.Signature.from_function # Removed in 3.11, can add if someone needs this
7977
multiprocessing.managers.SharedMemoryServer.create
@@ -148,19 +146,6 @@ queue.SimpleQueue.__init__
148146
xml.etree.ElementTree.XMLParser.__init__
149147
xml.etree.cElementTree.XMLParser.__init__
150148

151-
# Inherits __init__ from typing.Protocol
152-
importlib.abc.Traversable.__init__
153-
importlib.metadata.PackageMetadata.__init__
154-
importlib.metadata._meta.PackageMetadata.__init__
155-
importlib.metadata._meta.SimplePath.__init__
156-
typing.SupportsAbs.__init__
157-
typing.SupportsBytes.__init__
158-
typing.SupportsComplex.__init__
159-
typing.SupportsFloat.__init__
160-
typing.SupportsIndex.__init__
161-
typing.SupportsInt.__init__
162-
typing.SupportsRound.__init__
163-
164149
ftplib.FTP.trust_server_pasv_ipv4_address # Dangerous to use, intentionally undocumented, intentionally missing from typeshed. #6154
165150
os.PathLike.__class_getitem__ # PathLike is a protocol; we don't expect all PathLike classes to implement class_getitem
166151
types.CodeType.replace # stubtest thinks default values are None but None doesn't work at runtime

Diff for: tests/stubtest_allowlists/py311.txt

-31
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@ _collections_abc.MappingView.__class_getitem__
1212
_collections_abc.ValuesView.__reversed__
1313
_csv.Reader
1414
_csv.Writer
15-
_operator.attrgetter.__vectorcalloffset__
16-
_operator.itemgetter.__vectorcalloffset__
1715
argparse._MutuallyExclusiveGroup.add_mutually_exclusive_group
1816
asynchat.__warningregistry__ # Removal planned for 3.12, can add if someone needs this
1917
configparser.LegacyInterpolation.__init__
2018
enum.Enum.__init__
2119
fractions.Fraction.__new__ # overload is too complicated for stubtest to resolve
2220
ftplib.FTP.trust_server_pasv_ipv4_address
23-
functools.partial.__vectorcalloffset__
2421
ipaddress.IPv4Interface.hostmask
2522
ipaddress.IPv6Interface.hostmask
2623
ipaddress._BaseNetwork.broadcast_address
@@ -32,8 +29,6 @@ multiprocessing.managers.SharedMemoryServer.release_segment
3229
multiprocessing.managers.SharedMemoryServer.shutdown
3330
multiprocessing.managers.SharedMemoryServer.track_segment
3431
multiprocessing.spawn._main
35-
operator.attrgetter.__vectorcalloffset__
36-
operator.itemgetter.__vectorcalloffset__
3732
# platform.uname_result's processor field is now dynamically made to exist
3833
platform.uname_result.__match_args__
3934
platform.uname_result.__new__
@@ -93,7 +88,6 @@ os.path.join
9388
_collections_abc.AsyncGenerator.athrow # async at runtime, deliberately not in the stub, see #7491. Pos-only differences also.
9489
_weakref.ProxyType.__reversed__ # Doesn't really exist
9590
builtins.property.__set_name__ # Doesn't actually exist
96-
enum.StrEnum.value # read-only property at runtime but too magical for stubtest
9791
hmac.new # Stub is a white lie; see comments in the stub
9892
http.HTTPMethod.description # mutable instance attribute at runtime but we pretend it's a property
9993
pickle.Pickler.reducer_override # implemented in C pickler
@@ -103,25 +97,6 @@ types.GenericAlias.__mro_entries__
10397
weakref.ProxyType.__reversed__ # Doesn't really exist
10498
inspect._ParameterKind.description # Still exists, but stubtest can't see it
10599

106-
# Inherits __init__ from typing.Protocol (https://github.com/python/mypy/issues/12820)
107-
importlib.abc.Traversable.__init__
108-
importlib.metadata.EntryPoint.__init__
109-
importlib.metadata.PackageMetadata.__init__
110-
importlib.metadata._meta.PackageMetadata.__init__
111-
importlib.metadata._meta.SimplePath.__init__
112-
typing.SupportsAbs.__init__
113-
typing.SupportsBytes.__init__
114-
typing.SupportsComplex.__init__
115-
typing.SupportsFloat.__init__
116-
typing.SupportsIndex.__init__
117-
typing.SupportsInt.__init__
118-
typing.SupportsRound.__init__
119-
wsgiref.types.ErrorStream.__init__
120-
wsgiref.types.FileWrapper.__init__
121-
wsgiref.types.InputStream.__init__
122-
wsgiref.types.StartResponse.__init__
123-
wsgiref.types._Readable.__init__
124-
125100
# C signature is broader than what is actually accepted
126101
ast.Bytes.__new__
127102
ast.Ellipsis.__new__
@@ -169,12 +144,6 @@ typing._TypedDict.values
169144
# White lies around defaults
170145
dataclasses.KW_ONLY
171146

172-
# https://github.com/python/mypy/issues/13114
173-
wsgiref.types.WSGIEnvironment
174-
175-
# https://github.com/python/mypy/issues/12821 (stubtest bug with Callable type alias)
176-
wsgiref.types.WSGIApplication
177-
178147
# stubtest confuses stdlib distutils with setuptools-bundled distutils (#8410),
179148
# and the whole directory is going to be removed in 3.12 anyway
180149
distutils\..*

Diff for: tests/stubtest_allowlists/py37.txt

-8
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,12 @@ typing.NamedTuple._make
4545
typing.NamedTuple._replace
4646
typing._SpecialForm.__new__
4747
typing.runtime_checkable
48-
typing.Text.maketrans
4948
uuid.UUID.int
5049
uuid.UUID.is_safe
5150
uuid.getnode # undocumented, unused parameter getters that was later removed
5251
xml.etree.ElementTree.TreeBuilder.start # Discrepancy between Python and C modules, fixed in bpo-39495
5352
xml.etree.cElementTree.TreeBuilder.start # bpo-39495
5453

55-
sqlite3.OptimizedUnicode.maketrans
56-
sqlite3.dbapi2.OptimizedUnicode.maketrans
57-
5854
collections.Coroutine.cr_await
5955
collections.Coroutine.cr_code
6056
collections.Coroutine.cr_frame
@@ -141,10 +137,6 @@ collections.Set.__rxor__
141137

142138
builtins.memoryview.__iter__ # C type that implements __getitem__
143139
builtins.memoryview.cast # inspect.signature is incorrect about shape being kw-only
144-
sqlite3.dbapi2.Binary.__iter__ # C type that implements __getitem__
145-
sqlite3.dbapi2.Binary.cast # inspect.signature is incorrect about shape being kw-only
146-
sqlite3.Binary.__iter__ # C type that implements __getitem__
147-
sqlite3.Binary.cast # inspect.signature is incorrect about shape being kw-only
148140

149141
# C signature is broader than what is actually accepted
150142
queue.SimpleQueue.__init__

0 commit comments

Comments
 (0)