Bump mypy to 0.981 (#8796)

This commit is contained in:
Alex Waygood
2022-09-27 01:14:33 +01:00
committed by GitHub
parent 9abe56a19a
commit 48e76e8a56
29 changed files with 23 additions and 185 deletions

View File

@@ -5,7 +5,7 @@ flake8-bugbear==22.7.1 # must match .pre-commit-config.yaml
flake8-noqa==1.2.9 # must match .pre-commit-config.yaml
flake8-pyi==22.8.2 # must match .pre-commit-config.yaml
isort==5.10.1 # must match .pre-commit-config.yaml
mypy==0.971
mypy==0.981
packaging==21.3
pycln==2.1.1 # must match .pre-commit-config.yaml
pyyaml==6.0

View File

@@ -1952,7 +1952,7 @@ if sys.version_info >= (3, 11):
@overload
def subgroup(self: Self, __condition: Callable[[_BaseExceptionT_co], bool]) -> Self | None: ...
@overload
def split(
def split( # type: ignore[misc] # complaints about overlapping overloads
self: Self, __condition: type[_BaseExceptionT] | tuple[type[_BaseExceptionT], ...]
) -> tuple[BaseExceptionGroup[_BaseExceptionT] | None, Self | None]: ...
@overload
@@ -1972,7 +1972,7 @@ if sys.version_info >= (3, 11):
@overload
def subgroup(self: Self, __condition: Callable[[_ExceptionT_co], bool]) -> Self | None: ...
@overload # type: ignore[override]
def split(
def split( # type: ignore[misc] # complaints about overlapping overloads
self: Self, __condition: type[_ExceptionT] | tuple[type[_ExceptionT], ...]
) -> tuple[ExceptionGroup[_ExceptionT] | None, Self | None]: ...
@overload

View File

@@ -41,6 +41,9 @@ class _EntryPointBase(NamedTuple):
class EntryPoint(_EntryPointBase):
pattern: ClassVar[Pattern[str]]
if sys.version_info >= (3, 11):
def __init__(self, name: str, value: str, group: str) -> None: ...
def load(self) -> Any: ... # Callable[[], Any] or an importable module
@property
def extras(self) -> list[str]: ...

View File

@@ -1,4 +1,2 @@
# yaml._yaml is for backwards compatibility so none of it matters anyway
yaml._yaml.CEmitter.__pyx_vtable__
yaml._yaml.CParser.__pyx_vtable__
yaml._yaml.__test__

View File

@@ -14,10 +14,7 @@ sqlalchemy.ext.declarative.as_declarative
sqlalchemy.orm.collections.InstrumentedList.*
sqlalchemy.orm.collections.InstrumentedSet.*
sqlalchemy.orm.collections.MappedCollection.*
sqlalchemy.util.OrderedDict.get
sqlalchemy.util.StringIO.*
sqlalchemy.util.byte_buffer.*
sqlalchemy.util.column_dict.get
# method arguments starting with double underscores in the implementation
sqlalchemy.testing.resolve_lambda

View File

@@ -9,12 +9,6 @@ cffi.(api.)?FFI.buffer
# Exists at runtime, but missing from stubs
cffi.vengine_cpy.__warningregistry__
# Alias to io.StringIO, which has the same allowlist
cffi.recompiler.NativeIO.seek
cffi.recompiler.NativeIO.truncate
cffi.verifier.NativeIO.seek
cffi.verifier.NativeIO.truncate
# Unnecessary re-exports
cffi.cparser.COMMON_TYPES
cffi.verifier.__version_verifier_modules__

View File

@@ -2,7 +2,3 @@ hdbcli.dbapi.Error.errorcode
hdbcli.dbapi.Error.errortext
hdbcli.dbapi.Warning.errorcode
hdbcli.dbapi.Warning.errortext
# Similar issues to builtins.memoryview
hdbcli.dbapi.BINARY.__iter__
hdbcli.dbapi.BINARY.cast
hdbcli.dbapi.BINARY.__contains__

View File

@@ -1,3 +0,0 @@
# Misnamed first argument in implementation
html5lib._inputstream.EncodingBytes.__new__
html5lib._tokenizer.attributeMap.get

View File

@@ -72,7 +72,7 @@ class HTMLBinaryInputStream(HTMLUnicodeInputStream):
def detectEncodingMeta(self): ...
class EncodingBytes(bytes):
def __new__(cls, value): ...
def __new__(self, value): ...
def __init__(self, value) -> None: ...
def __iter__(self): ...
def __next__(self): ...

View File

@@ -1,2 +0,0 @@
# TODO: remove _FormatCheckCallable when mypy 0.980 is released
jsonschema._format._FormatCheckCallable

View File

@@ -4,14 +4,5 @@ keyboard._keyboard_event.KeyboardEvent.scan_code
# Defaults don't align with possible values
keyboard.mouse.on_button
keyboard.mouse.wait
# Private modules and tests
# TODO: Should this be allowlisted?
keyboard.__main__
keyboard._darwinkeyboard
keyboard._darwinmouse
keyboard._keyboard_tests
keyboard._mouse_tests
keyboard._nixcommon
keyboard._nixkeyboard
keyboard._nixmouse
keyboard._winkeyboard
keyboard._winmouse

View File

@@ -36,7 +36,3 @@ PyInstaller.utils.osx
PyInstaller.utils.run_tests
PyInstaller.utils.tests
PyInstaller.utils.win32.*
# Explicitly private implementation details
PyInstaller\._.*
PyInstaller.isolated._child
PyInstaller.utils._gitrevision

View File

@@ -1,21 +1,6 @@
redis.client.Pipeline.transaction # instance attribute has same name as superclass method
redis.ocsp # requires cryptography to be installed
# TypeAlias-related problems
redis.asyncio.client.CommandStackT
redis.asyncio.client.CommandT
redis.asyncio.client.PubSubHandler
redis.asyncio.connection.ExceptionMappingT
# Protocol-related problems
redis.asyncio.client.AsyncPubsubWorkerExceptionHandler.__init__
redis.asyncio.client.AsyncResponseCallbackProtocol.__init__
redis.asyncio.client.PubsubWorkerExceptionHandler.__init__
redis.asyncio.client.ResponseCallbackProtocol.__init__
redis.asyncio.connection.AsyncConnectCallbackProtocol.__init__
redis.asyncio.connection.ConnectCallbackProtocol.__init__
redis.typing.CommandsProtocol.__init__
# async def mismatch problems
redis.asyncio.client.Pipeline.command_info
redis.asyncio.client.Pipeline.debug_segfault
@@ -25,8 +10,6 @@ redis.asyncio.client.Pipeline.script_debug
redis.asyncio.client.Pipeline.shutdown
# unclear problems
redis.Sentinel.master_for
redis.Sentinel.slave_for
redis.asyncio.Sentinel.master_for
redis.asyncio.Sentinel.slave_for
redis.asyncio.sentinel.Sentinel.master_for

View File

@@ -21,5 +21,4 @@ six.viewkeys
six.viewvalues
# Unclear problems
six.Iterator.__init__
six.callable

View File

@@ -13,7 +13,9 @@ def logging_redirect_tqdm(
) -> _GeneratorContextManager[None]: ...
# TODO type *args, **kwargs here more precisely
# The type ignore is because mypy complains that the second overload will never be matched
# (I'm not sure that's true)
@overload
def tqdm_logging_redirect(*args, tqdm_class: Callable[..., _TqdmT], **kwargs) -> _GeneratorContextManager[_TqdmT]: ...
@overload
def tqdm_logging_redirect(*args, **kwargs) -> _GeneratorContextManager[std_tqdm[Incomplete]]: ...
def tqdm_logging_redirect(*args, **kwargs) -> _GeneratorContextManager[std_tqdm[Incomplete]]: ... # type: ignore[misc]

View File

@@ -1,15 +1,4 @@
# TODO: remove ResponseCls ignore when https://github.com/python/mypy/issues/13316 is closed
urllib3.HTTPConnectionPool.ResponseCls
urllib3.HTTPConnectionPool.__init__
urllib3.HTTPConnectionPool.urlopen
urllib3.HTTPSConnectionPool.__init__
urllib3.NullHandler
urllib3.PoolManager.connection_from_host
urllib3.PoolManager.connection_from_url
urllib3.PoolManager.urlopen
urllib3.ProxyManager.__init__
urllib3.ProxyManager.connection_from_host
urllib3.ProxyManager.urlopen
urllib3._collections.HTTPHeaderDict.from_httplib
urllib3._collections.HTTPHeaderDict.getlist
urllib3._collections.RLock
@@ -18,14 +7,11 @@ urllib3.connection.HTTPSConnection.__init__
urllib3.connection.VerifiedHTTPSConnection.__init__
urllib3.connection.VerifiedHTTPSConnection.set_cert
urllib3.connectionpool.ConnectionError
urllib3.connectionpool.HTTPConnection.request
# TODO: remove ResponseCls ignore when https://github.com/python/mypy/issues/13316 is closed
urllib3.connectionpool.HTTPConnectionPool.ResponseCls
urllib3.connectionpool.HTTPConnectionPool.__init__
urllib3.connectionpool.HTTPConnectionPool.urlopen
urllib3.connectionpool.HTTPSConnection.__init__
urllib3.connectionpool.HTTPSConnectionPool.__init__
urllib3.connectionpool.RequestMethods.request_encode_url
urllib3.connectionpool.VerifiedHTTPSConnection.__init__
urllib3.connectionpool.VerifiedHTTPSConnection.set_cert
urllib3.packages.ssl_match_hostname

View File

@@ -1 +0,0 @@
xxhash._xxhash

View File

@@ -13,7 +13,7 @@ from dataclasses import dataclass
from io import StringIO
from itertools import product
from pathlib import Path
from typing import TYPE_CHECKING, NamedTuple
from typing import TYPE_CHECKING, Any, NamedTuple
if TYPE_CHECKING:
from _typeshed import StrPath
@@ -157,7 +157,7 @@ def add_files(files: list[Path], seen: set[str], module: Path, args: TestConfig)
class MypyDistConf(NamedTuple):
module_name: str
values: dict
values: dict[str, dict[str, Any]]
# The configuration section in the metadata file looks like the following, with multiple module sections possible

View File

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

View File

@@ -35,8 +35,6 @@ _ctypes.dlopen
_ctypes.dlsym
posix.NGROUPS_MAX
posix.error.characters_written
resource.error.characters_written
select.POLLRDHUP
webbrowser.MacOSX.__init__

View File

@@ -44,10 +44,6 @@ winsound
# multiprocessing.popen_spawn_win32 exists on Linux but fail to import
multiprocessing.popen_spawn_win32
# Aliases for OSError
posix.error.characters_written
resource.error.characters_written
# Platform differences that cannot be captured by the type system
fcntl.I_[A-Z0-9_]+
os.SCHED_[A-Z_]+

View File

@@ -17,8 +17,7 @@ fractions.Fraction.__new__ # overload is too complicated for stubtest to resolv
gettext.install
gettext.translation
hmac.new # Stub is a white lie; see comments in the stub
importlib.metadata._meta.SimplePath.__div__ # See comments
importlib.metadata._meta.SimplePath.__truediv__ # See comments
importlib.metadata._meta.SimplePath.__truediv__ # See comments in the stub
ipaddress.IPv4Interface.hostmask
ipaddress.IPv6Interface.hostmask
ipaddress._BaseNetwork.broadcast_address
@@ -73,7 +72,6 @@ _csv.Writer
asynchat.__warningregistry__ # Removal planned for 3.12, can add if someone needs this
bdb.Breakpoint.clearBreakpoints
distutils.util.get_host_platform
functools.partial.__vectorcalloffset__ # undocumented implementation detail
inspect.Signature.from_builtin # Removed in 3.11, can add if someone needs this
inspect.Signature.from_function # Removed in 3.11, can add if someone needs this
multiprocessing.managers.SharedMemoryServer.create
@@ -148,19 +146,6 @@ queue.SimpleQueue.__init__
xml.etree.ElementTree.XMLParser.__init__
xml.etree.cElementTree.XMLParser.__init__
# Inherits __init__ from typing.Protocol
importlib.abc.Traversable.__init__
importlib.metadata.PackageMetadata.__init__
importlib.metadata._meta.PackageMetadata.__init__
importlib.metadata._meta.SimplePath.__init__
typing.SupportsAbs.__init__
typing.SupportsBytes.__init__
typing.SupportsComplex.__init__
typing.SupportsFloat.__init__
typing.SupportsIndex.__init__
typing.SupportsInt.__init__
typing.SupportsRound.__init__
ftplib.FTP.trust_server_pasv_ipv4_address # Dangerous to use, intentionally undocumented, intentionally missing from typeshed. #6154
os.PathLike.__class_getitem__ # PathLike is a protocol; we don't expect all PathLike classes to implement class_getitem
types.CodeType.replace # stubtest thinks default values are None but None doesn't work at runtime

View File

@@ -12,15 +12,12 @@ _collections_abc.MappingView.__class_getitem__
_collections_abc.ValuesView.__reversed__
_csv.Reader
_csv.Writer
_operator.attrgetter.__vectorcalloffset__
_operator.itemgetter.__vectorcalloffset__
argparse._MutuallyExclusiveGroup.add_mutually_exclusive_group
asynchat.__warningregistry__ # Removal planned for 3.12, can add if someone needs this
configparser.LegacyInterpolation.__init__
enum.Enum.__init__
fractions.Fraction.__new__ # overload is too complicated for stubtest to resolve
ftplib.FTP.trust_server_pasv_ipv4_address
functools.partial.__vectorcalloffset__
ipaddress.IPv4Interface.hostmask
ipaddress.IPv6Interface.hostmask
ipaddress._BaseNetwork.broadcast_address
@@ -32,8 +29,6 @@ multiprocessing.managers.SharedMemoryServer.release_segment
multiprocessing.managers.SharedMemoryServer.shutdown
multiprocessing.managers.SharedMemoryServer.track_segment
multiprocessing.spawn._main
operator.attrgetter.__vectorcalloffset__
operator.itemgetter.__vectorcalloffset__
# platform.uname_result's processor field is now dynamically made to exist
platform.uname_result.__match_args__
platform.uname_result.__new__
@@ -93,7 +88,6 @@ os.path.join
_collections_abc.AsyncGenerator.athrow # async at runtime, deliberately not in the stub, see #7491. Pos-only differences also.
_weakref.ProxyType.__reversed__ # Doesn't really exist
builtins.property.__set_name__ # Doesn't actually exist
enum.StrEnum.value # read-only property at runtime but too magical for stubtest
hmac.new # Stub is a white lie; see comments in the stub
http.HTTPMethod.description # mutable instance attribute at runtime but we pretend it's a property
pickle.Pickler.reducer_override # implemented in C pickler
@@ -103,25 +97,6 @@ types.GenericAlias.__mro_entries__
weakref.ProxyType.__reversed__ # Doesn't really exist
inspect._ParameterKind.description # Still exists, but stubtest can't see it
# Inherits __init__ from typing.Protocol (https://github.com/python/mypy/issues/12820)
importlib.abc.Traversable.__init__
importlib.metadata.EntryPoint.__init__
importlib.metadata.PackageMetadata.__init__
importlib.metadata._meta.PackageMetadata.__init__
importlib.metadata._meta.SimplePath.__init__
typing.SupportsAbs.__init__
typing.SupportsBytes.__init__
typing.SupportsComplex.__init__
typing.SupportsFloat.__init__
typing.SupportsIndex.__init__
typing.SupportsInt.__init__
typing.SupportsRound.__init__
wsgiref.types.ErrorStream.__init__
wsgiref.types.FileWrapper.__init__
wsgiref.types.InputStream.__init__
wsgiref.types.StartResponse.__init__
wsgiref.types._Readable.__init__
# C signature is broader than what is actually accepted
ast.Bytes.__new__
ast.Ellipsis.__new__
@@ -169,12 +144,6 @@ typing._TypedDict.values
# White lies around defaults
dataclasses.KW_ONLY
# https://github.com/python/mypy/issues/13114
wsgiref.types.WSGIEnvironment
# https://github.com/python/mypy/issues/12821 (stubtest bug with Callable type alias)
wsgiref.types.WSGIApplication
# stubtest confuses stdlib distutils with setuptools-bundled distutils (#8410),
# and the whole directory is going to be removed in 3.12 anyway
distutils\..*

View File

@@ -45,16 +45,12 @@ typing.NamedTuple._make
typing.NamedTuple._replace
typing._SpecialForm.__new__
typing.runtime_checkable
typing.Text.maketrans
uuid.UUID.int
uuid.UUID.is_safe
uuid.getnode # undocumented, unused parameter getters that was later removed
xml.etree.ElementTree.TreeBuilder.start # Discrepancy between Python and C modules, fixed in bpo-39495
xml.etree.cElementTree.TreeBuilder.start # bpo-39495
sqlite3.OptimizedUnicode.maketrans
sqlite3.dbapi2.OptimizedUnicode.maketrans
collections.Coroutine.cr_await
collections.Coroutine.cr_code
collections.Coroutine.cr_frame
@@ -141,10 +137,6 @@ collections.Set.__rxor__
builtins.memoryview.__iter__ # C type that implements __getitem__
builtins.memoryview.cast # inspect.signature is incorrect about shape being kw-only
sqlite3.dbapi2.Binary.__iter__ # C type that implements __getitem__
sqlite3.dbapi2.Binary.cast # inspect.signature is incorrect about shape being kw-only
sqlite3.Binary.__iter__ # C type that implements __getitem__
sqlite3.Binary.cast # inspect.signature is incorrect about shape being kw-only
# C signature is broader than what is actually accepted
queue.SimpleQueue.__init__

View File

@@ -57,13 +57,6 @@ typing.NamedTuple.__new__
typing.NamedTuple._asdict
typing.NamedTuple._make
typing.NamedTuple._replace
typing.SupportsAbs.__init__
typing.SupportsBytes.__init__
typing.SupportsComplex.__init__
typing.SupportsFloat.__init__
typing.SupportsIndex.__init__
typing.SupportsInt.__init__
typing.SupportsRound.__init__
typing._SpecialForm.__new__
weakref.WeakValueDictionary.update
xml.etree.ElementTree.TreeBuilder.start # Discrepancy between Python and C modules, fixed in bpo-39495
@@ -160,10 +153,6 @@ collections.Set.__rxor__
builtins.memoryview.__iter__ # C type that implements __getitem__
builtins.memoryview.cast # inspect.signature is incorrect about shape being kw-only
sqlite3.dbapi2.Binary.__iter__ # C type that implements __getitem__
sqlite3.dbapi2.Binary.cast # inspect.signature is incorrect about shape being kw-only
sqlite3.Binary.__iter__ # C type that implements __getitem__
sqlite3.Binary.cast # inspect.signature is incorrect about shape being kw-only
# C signature is broader than what is actually accepted
queue.SimpleQueue.__init__

View File

@@ -36,7 +36,6 @@ fractions.Fraction.__new__ # overload is too complicated for stubtest to resolv
gettext.install
gettext.translation
hmac.new # Stub is a white lie; see comments in the stub
importlib.abc.Traversable.__init__ # Inherits __init__ from typing.Protocol
inspect.Signature.from_builtin # Removed in 3.11, can add if someone needs this
inspect.Signature.from_function # Removed in 3.11, can add if someone needs this
ipaddress.IPv4Interface.hostmask
@@ -55,13 +54,6 @@ tkinter.Tk.split
types.CodeType.replace # stubtest thinks default values are None but None doesn't work at runtime
types.GenericAlias.__getattr__
types.GenericAlias.__call__ # Would be complicated to fix properly, Any could silence problems. #6392
typing.SupportsAbs.__init__
typing.SupportsBytes.__init__
typing.SupportsComplex.__init__
typing.SupportsFloat.__init__
typing.SupportsIndex.__init__
typing.SupportsInt.__init__
typing.SupportsRound.__init__
typing._TypedDict.__delitem__
typing._TypedDict.__ior__
typing._TypedDict.__or__
@@ -151,10 +143,6 @@ collections.Set.__rxor__
builtins.memoryview.__iter__ # C type that implements __getitem__
builtins.memoryview.cast # inspect.signature is incorrect about shape being kw-only
sqlite3.dbapi2.Binary.__iter__ # C type that implements __getitem__
sqlite3.dbapi2.Binary.cast # inspect.signature is incorrect about shape being kw-only
sqlite3.Binary.__iter__ # C type that implements __getitem__
sqlite3.Binary.cast # inspect.signature is incorrect about shape being kw-only
# C signature is broader than what is actually accepted
queue.SimpleQueue.__init__

View File

@@ -46,12 +46,11 @@ asyncio.locks.Condition.locked
asyncio.locks.Condition.release
asyncio.proactor_events.BaseProactorEventLoop.sock_recv # nbytes parameter has different name 'n' in implementation
asyncio.selector_events.BaseSelectorEventLoop.sock_recv # nbytes parameter has different name 'n' in implementation
builtins.OSError.characters_written # GetSetDescriptor that always raises AttributeError
builtins.dict.get
builtins.ellipsis # type is not exposed anywhere
builtins.function
builtins.memoryview.__contains__ # C type that implements __getitem__
sqlite3.dbapi2.Binary.__contains__ # C type that implements __getitem__
sqlite3.Binary.__contains__ # C type that implements __getitem__
builtins.object.__init__ # default C signature is incorrect
builtins.type.__dict__ # read-only but not actually a property; stubtest thinks it's a mutable attribute.
bz2.BZ2Decompressor.__init__ # function does not accept parameters but C signature is set
@@ -133,6 +132,9 @@ lib2to3.pytree.BasePattern.__new__
lib2to3.pytree.BasePattern.type
lib2to3.pytree.NegatedPattern.match
lib2to3.pytree.NegatedPattern.match_seq
# LC_MESSAGES is sometimes present in __all__, sometimes not,
# so stubtest will sometimes complain about exported names being different at runtime to the exported names in the stub
(locale)?
multiprocessing.JoinableQueue
multiprocessing.Queue
multiprocessing.SimpleQueue
@@ -389,14 +391,6 @@ builtins.super.__self__
builtins.super.__self_class__
builtins.super.__thisclass__
# Enum `name` and `value` are special properties that exists at runtime, but stubtest can't detect
# https://github.com/python/typeshed/pull/6576#issuecomment-992538677
enum.Enum.name
enum.Enum.value
enum.Flag.name
enum.Flag.value
enum.IntEnum.value
# These enums derive from (int, IntEnum) or (str, Enum).
pstats.SortKey.__new__
tkinter.EventType.__new__
@@ -423,17 +417,6 @@ ssl.PROTOCOL_SSLv2
ssl.PROTOCOL_SSLv3
ssl.RAND_egd
# GetSetDescriptor that always raises AttributeError
builtins.OSError.characters_written
# Aliases for OSError
_socket.error.characters_written
builtins.EnvironmentError.characters_written
builtins.IOError.characters_written
dbm.dumb.error.characters_written
os.error.characters_written
select.error.characters_written
socket.error.characters_written
collections.abc.* # Types are re-exported from _collections_abc, so errors should be fixed there
distutils.command.check.SilentReporter # only defined if docutils in installed
hmac.HMAC.blocksize # use block_size instead

View File

@@ -37,10 +37,6 @@ _ctypes.set_last_error
# Allowlist entries that cannot or should not be fixed
# ==========
# Aliases for OSError
builtins.WindowsError.characters_written
winreg.error.characters_written
# Modules that do not exist on Windows systems
_curses
_posixsubprocess

View File

@@ -17,7 +17,7 @@ try:
from termcolor import colored as colored
except ImportError:
def colored(s: str, _: str) -> str: # type: ignore
def colored(s: str, _: str) -> str: # type: ignore[misc]
return s