diff --git a/stdlib/ast.pyi b/stdlib/ast.pyi index 3a54d158affd..6c9dbd0162b8 100644 --- a/stdlib/ast.pyi +++ b/stdlib/ast.pyi @@ -5,21 +5,25 @@ from typing import Any, TypeVar, overload from typing_extensions import Literal if sys.version_info >= (3, 8): - class Num(Constant): + class _ABC(type): + if sys.version_info >= (3, 9): + def __init__(cls, *args: object) -> None: ... + + class Num(Constant, metaclass=_ABC): value: complex - class Str(Constant): + class Str(Constant, metaclass=_ABC): value: str # Aliases for value, for backwards compatibility s: str - class Bytes(Constant): + class Bytes(Constant, metaclass=_ABC): value: bytes # Aliases for value, for backwards compatibility s: bytes - class NameConstant(Constant): ... - class Ellipsis(Constant): ... + class NameConstant(Constant, metaclass=_ABC): ... + class Ellipsis(Constant, metaclass=_ABC): ... if sys.version_info >= (3, 9): class slice(AST): ... diff --git a/stdlib/contextlib.pyi b/stdlib/contextlib.pyi index 83f1cbf08152..6a846ad618c3 100644 --- a/stdlib/contextlib.pyi +++ b/stdlib/contextlib.pyi @@ -1,3 +1,4 @@ +import abc import sys from _typeshed import Self, StrOrBytesPath from abc import abstractmethod @@ -133,7 +134,9 @@ class _RedirectStream(AbstractContextManager[_T_io]): class redirect_stdout(_RedirectStream[_T_io]): ... class redirect_stderr(_RedirectStream[_T_io]): ... -class ExitStack: +# In reality this is a subclass of `AbstractContextManager`; +# see #7961 for why we don't do that in the stub +class ExitStack(metaclass=abc.ABCMeta): def __init__(self) -> None: ... def enter_context(self, cm: AbstractContextManager[_T]) -> _T: ... def push(self, exit: _CM_EF) -> _CM_EF: ... @@ -148,7 +151,9 @@ class ExitStack: _ExitCoroFunc: TypeAlias = Callable[[type[BaseException] | None, BaseException | None, TracebackType | None], Awaitable[bool]] _ACM_EF = TypeVar("_ACM_EF", bound=AbstractAsyncContextManager[Any] | _ExitCoroFunc) -class AsyncExitStack: +# In reality this is a subclass of `AbstractAsyncContextManager`; +# see #7961 for why we don't do that in the stub +class AsyncExitStack(metaclass=abc.ABCMeta): def __init__(self) -> None: ... def enter_context(self, cm: AbstractContextManager[_T]) -> _T: ... async def enter_async_context(self, cm: AbstractAsyncContextManager[_T]) -> _T: ...