From 433204fb8f5e47e419ebcede3f17ac4e86a9c618 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 4 Sep 2023 15:39:11 +0100 Subject: [PATCH] py312: Fix stubtest nits in `typing`/`typing_extensions` (#10659) --- stdlib/typing.pyi | 9 ++++++-- tests/stubtest_allowlists/py310.txt | 3 +++ tests/stubtest_allowlists/py311.txt | 3 +++ tests/stubtest_allowlists/py312.txt | 28 +++++++++++++----------- tests/stubtest_allowlists/py38.txt | 1 + tests/stubtest_allowlists/py39.txt | 1 + tests/stubtest_allowlists/py3_common.txt | 1 - 7 files changed, 30 insertions(+), 16 deletions(-) diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index a9bffdf52..2c1ebe6d7 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -126,6 +126,9 @@ if sys.version_info >= (3, 11): "reveal_type", ] +if sys.version_info >= (3, 12): + __all__ += ["TypeAliasType", "override"] + ContextManager = AbstractContextManager AsyncContextManager = AbstractAsyncContextManager @@ -323,7 +326,9 @@ AnyStr = TypeVar("AnyStr", str, bytes) # noqa: Y001 # Technically in 3.7 this inherited from GenericMeta. But let's not reflect that, since # type checkers tend to assume that Protocols all have the ABCMeta metaclass. -class _ProtocolMeta(ABCMeta): ... +class _ProtocolMeta(ABCMeta): + if sys.version_info >= (3, 12): + def __init__(cls, *args: Any, **kwargs: Any) -> None: ... # Abstract base classes. @@ -945,7 +950,7 @@ if sys.version_info >= (3, 10): def _type_repr(obj: object) -> str: ... if sys.version_info >= (3, 12): - def override(__arg: _F) -> _F: ... + def override(__method: _F) -> _F: ... @_final class TypeAliasType: def __init__( diff --git a/tests/stubtest_allowlists/py310.txt b/tests/stubtest_allowlists/py310.txt index 6dd6ef21f..d888015b2 100644 --- a/tests/stubtest_allowlists/py310.txt +++ b/tests/stubtest_allowlists/py310.txt @@ -162,3 +162,6 @@ pkgutil.ImpImporter\..* pkgutil.ImpLoader\..* types.CodeType.replace # stubtest thinks default values are None but None doesn't work at runtime + +# https://github.com/python/mypy/issues/15302 +typing_extensions\.override diff --git a/tests/stubtest_allowlists/py311.txt b/tests/stubtest_allowlists/py311.txt index f903121a9..2153f4e17 100644 --- a/tests/stubtest_allowlists/py311.txt +++ b/tests/stubtest_allowlists/py311.txt @@ -123,3 +123,6 @@ asynchat.async_chat.use_encoding asynchat.find_prefix_at_end pkgutil.ImpImporter\..* pkgutil.ImpLoader\..* + +# https://github.com/python/mypy/issues/15302 +typing_extensions\.override diff --git a/tests/stubtest_allowlists/py312.txt b/tests/stubtest_allowlists/py312.txt index 6f70c9d8c..3647a7360 100644 --- a/tests/stubtest_allowlists/py312.txt +++ b/tests/stubtest_allowlists/py312.txt @@ -18,19 +18,6 @@ importlib.metadata._meta.SimplePath.parent poplib.POP3_SSL.__init__ smtplib.SMTP.starttls smtplib.SMTP_SSL.__init__ -typing.ParamSpec.__mro_entries__ -typing.ParamSpecArgs.__mro_entries__ -typing.ParamSpecKwargs.__mro_entries__ -typing.SupportsAbs.__type_params__ -typing.SupportsRound.__type_params__ -typing.TypeVar.__mro_entries__ -typing.TypeVarTuple.__mro_entries__ -typing._ProtocolMeta.__init__ -typing.__all__ -typing.override -typing_extensions.Protocol -typing_extensions.SupportsAbs.__type_params__ -typing_extensions.SupportsRound.__type_params__ urllib.request.AbstractHTTPHandler.__init__ urllib.request.HTTPSHandler.__init__ @@ -135,6 +122,21 @@ typing\._SpecialForm.* typing\.NamedTuple typing\.LiteralString typing\.Annotated +typing_extensions\.Protocol + +# These only exist to give a better error message if you try to subclass an instance +typing.ParamSpec.__mro_entries__ +typing.ParamSpecArgs.__mro_entries__ +typing.ParamSpecKwargs.__mro_entries__ +typing.TypeVar.__mro_entries__ +typing.TypeVarTuple.__mro_entries__ + +# TODO: mypy should infer that this attribute is inherited from builtins.type; +# why doesn't it infer this? +typing.SupportsAbs.__type_params__ +typing.SupportsRound.__type_params__ +typing_extensions.SupportsAbs.__type_params__ +typing_extensions.SupportsRound.__type_params__ # These two should be removable after 3.12rc2 is released: types.CodeType.replace # stubtest thinks default values are None but None doesn't work at runtime diff --git a/tests/stubtest_allowlists/py38.txt b/tests/stubtest_allowlists/py38.txt index de2c1a9e1..aba802f73 100644 --- a/tests/stubtest_allowlists/py38.txt +++ b/tests/stubtest_allowlists/py38.txt @@ -144,6 +144,7 @@ types.WrapperDescriptorType.__get__ typing_extensions\.assert_never typing_extensions\.assert_type typing_extensions\.reveal_type +typing_extensions\.override # We lie about the existence of these methods .*.__buffer__ diff --git a/tests/stubtest_allowlists/py39.txt b/tests/stubtest_allowlists/py39.txt index aaa75a0c1..767da783b 100644 --- a/tests/stubtest_allowlists/py39.txt +++ b/tests/stubtest_allowlists/py39.txt @@ -131,6 +131,7 @@ types.WrapperDescriptorType.__get__ typing_extensions\.assert_never typing_extensions\.assert_type typing_extensions\.reveal_type +typing_extensions\.override # Super-special typing primitives typing\.NamedTuple diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index c312cd2ca..f59bc6623 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -463,7 +463,6 @@ typing_extensions.NewType.__mro_entries__ # just exists for an error message # https://github.com/python/mypy/issues/15302 typing_extensions.NewType.__call__ typing_extensions\.deprecated -typing_extensions\.override typing_extensions\.get_protocol_members typing_extensions\.is_protocol