Avoid unnecessary forward refs in class definitions (#10124)

This commit is contained in:
Alex Waygood
2023-05-01 15:50:50 +01:00
committed by GitHub
parent 277532219f
commit e816acffdd
5 changed files with 98 additions and 99 deletions

View File

@@ -208,13 +208,6 @@ def unique(enumeration: _EnumerationT) -> _EnumerationT: ...
_auto_null: Any
# subclassing IntFlag so it picks up all implemented base functions, best modeling behavior of enum.auto()
class auto(IntFlag):
_value_: Any
@_magic_enum_attr
def value(self) -> Any: ...
def __new__(cls) -> Self: ...
class Flag(Enum):
_name_: str | None # type: ignore[assignment]
_value_: int
@@ -235,27 +228,6 @@ class Flag(Enum):
__rand__ = __and__
__rxor__ = __xor__
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): # 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): # 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, value: str) -> Self: ...
@@ -289,3 +261,31 @@ if sys.version_info >= (3, 11):
def global_enum(cls: _EnumerationT, update_str: bool = False) -> _EnumerationT: ...
def global_enum_repr(self: Enum) -> str: ...
def global_flag_repr(self: Flag) -> str: ...
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): # 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): # 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__
# subclassing IntFlag so it picks up all implemented base functions, best modeling behavior of enum.auto()
class auto(IntFlag):
_value_: Any
@_magic_enum_attr
def value(self) -> Any: ...
def __new__(cls) -> Self: ...