From e3a79d0ce6e6a7dbcc4b20a5623cc298b2bf0920 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sat, 27 Oct 2018 17:54:56 +0200 Subject: [PATCH] Remove third_party/3/enum.py (#2563) All Python 3 versions supported by typeshed (3.4+) have enum as part of the standard library. Make the third-party Python 2 version consistent with the Python 3 version. --- stdlib/3/enum.pyi | 2 +- tests/check_consistent.py | 2 +- third_party/2/enum.pyi | 31 ++++++++++++++++++- third_party/3/enum.pyi | 65 --------------------------------------- 4 files changed, 32 insertions(+), 68 deletions(-) delete mode 100644 third_party/3/enum.pyi diff --git a/stdlib/3/enum.pyi b/stdlib/3/enum.pyi index f5b8dd10d..febc0dd5a 100644 --- a/stdlib/3/enum.pyi +++ b/stdlib/3/enum.pyi @@ -1,4 +1,4 @@ -# NB: third_party/3/enum.pyi and stdlib/3.4/enum.pyi must remain consistent! +# NB: third_party/2/enum.pyi and stdlib/3.4/enum.pyi must remain consistent! import sys from typing import Any, Iterator, List, Mapping, Type, TypeVar, Union from abc import ABCMeta diff --git a/tests/check_consistent.py b/tests/check_consistent.py index 08e9bd5a1..249045428 100755 --- a/tests/check_consistent.py +++ b/tests/check_consistent.py @@ -14,7 +14,7 @@ consistent_files = [ {'stdlib/2and3/pyexpat/errors.pyi', 'stdlib/2and3/xml/parsers/expat/errors.pyi'}, {'stdlib/2and3/pyexpat/model.pyi', 'stdlib/2and3/xml/parsers/expat/model.pyi'}, {'stdlib/3/ntpath.pyi', 'stdlib/3/posixpath.pyi', 'stdlib/3/macpath.pyi', 'stdlib/3/posixpath.pyi'}, - {'stdlib/3/enum.pyi', 'third_party/3/enum.pyi'}, + {'stdlib/3/enum.pyi', 'third_party/2/enum.pyi'}, {'stdlib/2/os/path.pyi', 'stdlib/3/os/path.pyi'}, {'stdlib/3/unittest/mock.pyi', 'third_party/2and3/mock.pyi'}, {'stdlib/3/concurrent/__init__.pyi', 'third_party/2/concurrent/__init__.pyi'}, diff --git a/third_party/2/enum.pyi b/third_party/2/enum.pyi index a04486162..febc0dd5a 100644 --- a/third_party/2/enum.pyi +++ b/third_party/2/enum.pyi @@ -1,4 +1,6 @@ -from typing import List, Any, TypeVar, Union, Iterable, Iterator, TypeVar, Generic, Type, Sized, Reversible, Container, Mapping +# NB: third_party/2/enum.pyi and stdlib/3.4/enum.pyi must remain consistent! +import sys +from typing import Any, Iterator, List, Mapping, Type, TypeVar, Union from abc import ABCMeta _T = TypeVar('_T') @@ -34,3 +36,30 @@ class IntEnum(int, Enum): value = ... # type: int def unique(enumeration: _S) -> _S: ... + +if sys.version_info >= (3, 6): + _auto_null = ... # type: Any + + # subclassing IntFlag so it picks up all implemented base functions, best modeling behavior of enum.auto() + class auto(IntFlag): + value = ... # type: Any + + class Flag(Enum): + def __contains__(self: _T, other: _T) -> bool: ... + def __repr__(self) -> str: ... + def __str__(self) -> str: ... + def __bool__(self) -> bool: ... + def __or__(self: _T, other: _T) -> _T: ... + def __and__(self: _T, other: _T) -> _T: ... + def __xor__(self: _T, other: _T) -> _T: ... + def __invert__(self: _T) -> _T: ... + + # The `type: ignore` comment is needed because mypy considers the type + # signatures of several methods defined in int and Flag to be incompatible. + class IntFlag(int, Flag): # type: ignore + def __or__(self: _T, other: Union[int, _T]) -> _T: ... + def __and__(self: _T, other: Union[int, _T]) -> _T: ... + def __xor__(self: _T, other: Union[int, _T]) -> _T: ... + __ror__ = __or__ + __rand__ = __and__ + __rxor__ = __xor__ diff --git a/third_party/3/enum.pyi b/third_party/3/enum.pyi deleted file mode 100644 index f5b8dd10d..000000000 --- a/third_party/3/enum.pyi +++ /dev/null @@ -1,65 +0,0 @@ -# NB: third_party/3/enum.pyi and stdlib/3.4/enum.pyi must remain consistent! -import sys -from typing import Any, Iterator, List, Mapping, Type, TypeVar, Union -from abc import ABCMeta - -_T = TypeVar('_T') -_S = TypeVar('_S', bound=Type[Enum]) - -# Note: EnumMeta actually subclasses type directly, not ABCMeta. -# This is a temporary workaround to allow multiple creation of enums with builtins -# such as str as mixins, which due to the handling of ABCs of builtin types, cause -# spurious inconsistent metaclass structure. See #1595. -# Structurally: Iterable[T], Reversible[T], Container[T] where T is the enum itself -class EnumMeta(ABCMeta): - def __iter__(self: Type[_T]) -> Iterator[_T]: ... - def __reversed__(self: Type[_T]) -> Iterator[_T]: ... - def __contains__(self: Type[_T], member: object) -> bool: ... - def __getitem__(self: Type[_T], name: str) -> _T: ... - @property - def __members__(self: Type[_T]) -> Mapping[str, _T]: ... - def __len__(self) -> int: ... - -class Enum(metaclass=EnumMeta): - def __new__(cls: Type[_T], value: object) -> _T: ... - def __repr__(self) -> str: ... - def __str__(self) -> str: ... - def __dir__(self) -> List[str]: ... - def __format__(self, format_spec: str) -> str: ... - def __hash__(self) -> Any: ... - def __reduce_ex__(self, proto: object) -> Any: ... - - name = ... # type: str - value = ... # type: Any - -class IntEnum(int, Enum): - value = ... # type: int - -def unique(enumeration: _S) -> _S: ... - -if sys.version_info >= (3, 6): - _auto_null = ... # type: Any - - # subclassing IntFlag so it picks up all implemented base functions, best modeling behavior of enum.auto() - class auto(IntFlag): - value = ... # type: Any - - class Flag(Enum): - def __contains__(self: _T, other: _T) -> bool: ... - def __repr__(self) -> str: ... - def __str__(self) -> str: ... - def __bool__(self) -> bool: ... - def __or__(self: _T, other: _T) -> _T: ... - def __and__(self: _T, other: _T) -> _T: ... - def __xor__(self: _T, other: _T) -> _T: ... - def __invert__(self: _T) -> _T: ... - - # The `type: ignore` comment is needed because mypy considers the type - # signatures of several methods defined in int and Flag to be incompatible. - class IntFlag(int, Flag): # type: ignore - def __or__(self: _T, other: Union[int, _T]) -> _T: ... - def __and__(self: _T, other: Union[int, _T]) -> _T: ... - def __xor__(self: _T, other: Union[int, _T]) -> _T: ... - __ror__ = __or__ - __rand__ = __and__ - __rxor__ = __xor__