Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump mypy to 0.981 #8796

Merged
merged 15 commits into from Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements-tests.txt
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions stdlib/builtins.pyi
Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe these new mypy errors are already fixed on mypy master, by python/mypy#13461. Unfortunately, it doesn't look like that PR made it into 0.981 (cc. @hauntsaninja, @ilevkivskyi)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @jhance if people will complain about this, we will need to CP it and release 0.982.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlexWaygood mypy 0.982 was released with the fix for this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Molkree thanks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mypy was successfully bumped to 0.982 in #8831; the type ignores are gone again 🎉

Thanks @ilevkivskyi for the work on the patch release!

self: Self, __condition: type[_BaseExceptionT] | tuple[type[_BaseExceptionT], ...]
) -> tuple[BaseExceptionGroup[_BaseExceptionT] | None, Self | None]: ...
@overload
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions stdlib/importlib/metadata/__init__.pyi
Expand Up @@ -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: ...

Comment on lines +44 to +46
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The allowlist entry had a comment saying that it was to do with Protocol.__init__, so I thought I could safely remove the allowlist entry now that we were bumping to mypy 0.981. Actually the comment was wrong, the allowlist entry had nothing to do with Protocol.__init__. But I figured fixing the allowlist entry was just as easy as correcting the comment next to the entry.

def load(self) -> Any: ... # Callable[[], Any] or an importable module
@property
def extras(self) -> list[str]: ...
Expand Down
2 changes: 0 additions & 2 deletions stubs/PyYAML/@tests/stubtest_allowlist.txt
@@ -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__
3 changes: 0 additions & 3 deletions stubs/SQLAlchemy/@tests/stubtest_allowlist.txt
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions stubs/cffi/@tests/stubtest_allowlist.txt
Expand Up @@ -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__
4 changes: 0 additions & 4 deletions stubs/hdbcli/@tests/stubtest_allowlist.txt
Expand Up @@ -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__
3 changes: 0 additions & 3 deletions stubs/html5lib/@tests/stubtest_allowlist.txt

This file was deleted.

2 changes: 1 addition & 1 deletion stubs/html5lib/html5lib/_inputstream.pyi
Expand Up @@ -72,7 +72,7 @@ class HTMLBinaryInputStream(HTMLUnicodeInputStream):
def detectEncodingMeta(self): ...

class EncodingBytes(bytes):
def __new__(cls, value): ...
def __new__(self, value): ...
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change isn't strictly related to the mypy bump, but it was a very easy allowlist entry to fix, and it means that we can delete the whole allowlist for html5lib since the other allowlist entry is now unused as of mypy 0.981.

def __init__(self, value) -> None: ...
def __iter__(self): ...
def __next__(self): ...
Expand Down
2 changes: 0 additions & 2 deletions stubs/jsonschema/@tests/stubtest_allowlist.txt

This file was deleted.

11 changes: 1 addition & 10 deletions stubs/keyboard/@tests/stubtest_allowlist.txt
Expand Up @@ -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
4 changes: 0 additions & 4 deletions stubs/pyinstaller/@tests/stubtest_allowlist.txt
Expand Up @@ -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
17 changes: 0 additions & 17 deletions stubs/redis/@tests/stubtest_allowlist.txt
@@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion stubs/six/@tests/stubtest_allowlist.txt
Expand Up @@ -21,5 +21,4 @@ six.viewkeys
six.viewvalues

# Unclear problems
six.Iterator.__init__
six.callable
4 changes: 3 additions & 1 deletion stubs/tqdm/tqdm/contrib/logging.pyi
Expand Up @@ -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]
14 changes: 0 additions & 14 deletions stubs/urllib3/@tests/stubtest_allowlist.txt
@@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion stubs/xxhash/@tests/stubtest_allowlist.txt

This file was deleted.

4 changes: 2 additions & 2 deletions tests/mypy_test.py
Expand Up @@ -13,7 +13,7 @@
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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion tests/regr_test.py
Expand Up @@ -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")])
Expand Down
2 changes: 0 additions & 2 deletions tests/stubtest_allowlists/darwin.txt
Expand Up @@ -35,8 +35,6 @@ _ctypes.dlopen
_ctypes.dlsym

posix.NGROUPS_MAX
posix.error.characters_written
resource.error.characters_written
select.POLLRDHUP
webbrowser.MacOSX.__init__

Expand Down
4 changes: 0 additions & 4 deletions tests/stubtest_allowlists/linux.txt
Expand Up @@ -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_]+
Expand Down
17 changes: 1 addition & 16 deletions tests/stubtest_allowlists/py310.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
31 changes: 0 additions & 31 deletions tests/stubtest_allowlists/py311.txt
Expand Up @@ -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
Expand All @@ -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__
Expand Down Expand Up @@ -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
Expand All @@ -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__
Expand Down Expand Up @@ -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\..*
8 changes: 0 additions & 8 deletions tests/stubtest_allowlists/py37.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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__
Expand Down