Skip to content

Add missing metaclasses #8497

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

Merged
merged 9 commits into from
Aug 8, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions stdlib/ast.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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): ...
Expand Down
9 changes: 7 additions & 2 deletions stdlib/contextlib.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import abc
import sys
from _typeshed import Self, StrOrBytesPath
from abc import abstractmethod
Expand Down Expand Up @@ -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: ...
Expand All @@ -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: ...
Expand Down