mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 20:54:28 +08:00
Use typing_extensions.Self in the stdlib (#9694)
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import _typeshed
|
||||
import sys
|
||||
import types
|
||||
from _typeshed import Self, SupportsKeysAndGetItem, Unused
|
||||
from _typeshed import SupportsKeysAndGetItem, Unused
|
||||
from abc import ABCMeta
|
||||
from builtins import property as _builtins_property
|
||||
from collections.abc import Iterable, Iterator, Mapping
|
||||
from typing import Any, Generic, TypeVar, overload
|
||||
from typing_extensions import Literal, TypeAlias
|
||||
from typing_extensions import Literal, Self, TypeAlias
|
||||
|
||||
__all__ = ["EnumMeta", "Enum", "IntEnum", "Flag", "IntFlag", "auto", "unique"]
|
||||
|
||||
@@ -80,7 +81,7 @@ class _EnumDict(dict[str, Any]):
|
||||
class EnumMeta(ABCMeta):
|
||||
if sys.version_info >= (3, 11):
|
||||
def __new__(
|
||||
metacls: type[Self],
|
||||
metacls: type[_typeshed.Self],
|
||||
cls: str,
|
||||
bases: tuple[type, ...],
|
||||
classdict: _EnumDict,
|
||||
@@ -88,11 +89,13 @@ class EnumMeta(ABCMeta):
|
||||
boundary: FlagBoundary | None = None,
|
||||
_simple: bool = False,
|
||||
**kwds: Any,
|
||||
) -> Self: ...
|
||||
) -> _typeshed.Self: ...
|
||||
elif sys.version_info >= (3, 9):
|
||||
def __new__(metacls: type[Self], cls: str, bases: tuple[type, ...], classdict: _EnumDict, **kwds: Any) -> Self: ...
|
||||
def __new__(
|
||||
metacls: type[_typeshed.Self], cls: str, bases: tuple[type, ...], classdict: _EnumDict, **kwds: Any
|
||||
) -> _typeshed.Self: ...
|
||||
else:
|
||||
def __new__(metacls: type[Self], cls: str, bases: tuple[type, ...], classdict: _EnumDict) -> Self: ...
|
||||
def __new__(metacls: type[_typeshed.Self], cls: str, bases: tuple[type, ...], classdict: _EnumDict) -> _typeshed.Self: ...
|
||||
|
||||
if sys.version_info >= (3, 9):
|
||||
@classmethod
|
||||
@@ -174,7 +177,7 @@ class Enum(metaclass=EnumMeta):
|
||||
# However, using `Any` causes too many false-positives for those using mypy's `--disallow-any-expr`
|
||||
# (see #7752, #2539, mypy/#5788),
|
||||
# and in practice using `object` here has the same effect as using `Any`.
|
||||
def __new__(cls: type[Self], value: object) -> Self: ...
|
||||
def __new__(cls, value: object) -> Self: ...
|
||||
def __dir__(self) -> list[str]: ...
|
||||
def __format__(self, format_spec: str) -> str: ...
|
||||
def __reduce_ex__(self, proto: Unused) -> tuple[Any, ...]: ...
|
||||
@@ -191,7 +194,7 @@ class IntEnum(int, _IntEnumBase):
|
||||
_value_: int
|
||||
@_magic_enum_attr
|
||||
def value(self) -> int: ...
|
||||
def __new__(cls: type[Self], value: int) -> Self: ...
|
||||
def __new__(cls, value: int) -> Self: ...
|
||||
|
||||
def unique(enumeration: _EnumerationT) -> _EnumerationT: ...
|
||||
|
||||
@@ -202,7 +205,7 @@ class auto(IntFlag):
|
||||
_value_: Any
|
||||
@_magic_enum_attr
|
||||
def value(self) -> Any: ...
|
||||
def __new__(cls: type[Self]) -> Self: ...
|
||||
def __new__(cls) -> Self: ...
|
||||
|
||||
class Flag(Enum):
|
||||
_name_: str | None # type: ignore[assignment]
|
||||
@@ -211,14 +214,14 @@ class Flag(Enum):
|
||||
def name(self) -> str | None: ... # type: ignore[override]
|
||||
@_magic_enum_attr
|
||||
def value(self) -> int: ...
|
||||
def __contains__(self: Self, other: Self) -> bool: ...
|
||||
def __contains__(self, other: Self) -> bool: ...
|
||||
def __bool__(self) -> bool: ...
|
||||
def __or__(self: Self, other: Self) -> Self: ...
|
||||
def __and__(self: Self, other: Self) -> Self: ...
|
||||
def __xor__(self: Self, other: Self) -> Self: ...
|
||||
def __invert__(self: Self) -> Self: ...
|
||||
def __or__(self, other: Self) -> Self: ...
|
||||
def __and__(self, other: Self) -> Self: ...
|
||||
def __xor__(self, other: Self) -> Self: ...
|
||||
def __invert__(self) -> Self: ...
|
||||
if sys.version_info >= (3, 11):
|
||||
def __iter__(self: Self) -> Iterator[Self]: ...
|
||||
def __iter__(self) -> Iterator[Self]: ...
|
||||
def __len__(self) -> int: ...
|
||||
__ror__ = __or__
|
||||
__rand__ = __and__
|
||||
@@ -226,28 +229,28 @@ class Flag(Enum):
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
# The body of the class is the same, but the base classes are different.
|
||||
class IntFlag(int, ReprEnum, Flag, boundary=KEEP):
|
||||
def __new__(cls: type[Self], value: int) -> Self: ...
|
||||
def __or__(self: Self, other: int) -> Self: ...
|
||||
def __and__(self: Self, other: int) -> Self: ...
|
||||
def __xor__(self: Self, other: int) -> Self: ...
|
||||
class IntFlag(int, ReprEnum, Flag, boundary=KEEP): # type: ignore[misc] # complaints about incompatible bases
|
||||
def __new__(cls, value: int) -> Self: ...
|
||||
def __or__(self, other: int) -> Self: ...
|
||||
def __and__(self, other: int) -> Self: ...
|
||||
def __xor__(self, other: int) -> Self: ...
|
||||
__ror__ = __or__
|
||||
__rand__ = __and__
|
||||
__rxor__ = __xor__
|
||||
|
||||
else:
|
||||
class IntFlag(int, Flag):
|
||||
def __new__(cls: type[Self], value: int) -> Self: ...
|
||||
def __or__(self: Self, other: int) -> Self: ...
|
||||
def __and__(self: Self, other: int) -> Self: ...
|
||||
def __xor__(self: Self, other: int) -> Self: ...
|
||||
class IntFlag(int, Flag): # type: ignore[misc] # complaints about incompatible bases
|
||||
def __new__(cls, value: int) -> Self: ...
|
||||
def __or__(self, other: int) -> Self: ...
|
||||
def __and__(self, other: int) -> Self: ...
|
||||
def __xor__(self, other: int) -> Self: ...
|
||||
__ror__ = __or__
|
||||
__rand__ = __and__
|
||||
__rxor__ = __xor__
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
class StrEnum(str, ReprEnum):
|
||||
def __new__(cls: type[Self], value: str) -> Self: ...
|
||||
def __new__(cls, value: str) -> Self: ...
|
||||
_value_: str
|
||||
@_magic_enum_attr
|
||||
def value(self) -> str: ...
|
||||
|
||||
Reference in New Issue
Block a user