|
1 |
| -from typing import List, Any, TypeVar, Union, Iterable, Iterator, TypeVar, Generic, Type, Sized, Reversible, Container, Mapping |
| 1 | +# NB: third_party/2/enum.pyi and stdlib/3.4/enum.pyi must remain consistent! |
| 2 | +import sys |
| 3 | +from typing import Any, Iterator, List, Mapping, Type, TypeVar, Union |
2 | 4 | from abc import ABCMeta
|
3 | 5 |
|
4 | 6 | _T = TypeVar('_T')
|
@@ -34,3 +36,30 @@ class IntEnum(int, Enum):
|
34 | 36 | value = ... # type: int
|
35 | 37 |
|
36 | 38 | def unique(enumeration: _S) -> _S: ...
|
| 39 | + |
| 40 | +if sys.version_info >= (3, 6): |
| 41 | + _auto_null = ... # type: Any |
| 42 | + |
| 43 | + # subclassing IntFlag so it picks up all implemented base functions, best modeling behavior of enum.auto() |
| 44 | + class auto(IntFlag): |
| 45 | + value = ... # type: Any |
| 46 | + |
| 47 | + class Flag(Enum): |
| 48 | + def __contains__(self: _T, other: _T) -> bool: ... |
| 49 | + def __repr__(self) -> str: ... |
| 50 | + def __str__(self) -> str: ... |
| 51 | + def __bool__(self) -> bool: ... |
| 52 | + def __or__(self: _T, other: _T) -> _T: ... |
| 53 | + def __and__(self: _T, other: _T) -> _T: ... |
| 54 | + def __xor__(self: _T, other: _T) -> _T: ... |
| 55 | + def __invert__(self: _T) -> _T: ... |
| 56 | + |
| 57 | + # The `type: ignore` comment is needed because mypy considers the type |
| 58 | + # signatures of several methods defined in int and Flag to be incompatible. |
| 59 | + class IntFlag(int, Flag): # type: ignore |
| 60 | + def __or__(self: _T, other: Union[int, _T]) -> _T: ... |
| 61 | + def __and__(self: _T, other: Union[int, _T]) -> _T: ... |
| 62 | + def __xor__(self: _T, other: Union[int, _T]) -> _T: ... |
| 63 | + __ror__ = __or__ |
| 64 | + __rand__ = __and__ |
| 65 | + __rxor__ = __xor__ |
0 commit comments