Skip to content

Commit bbc7594

Browse files
author
Lukasz Langa
committed
Add Flag, IntFlag and auto to enum stubs
Fixes python/mypy#2609
1 parent f8717cc commit bbc7594

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

stdlib/3.4/enum.pyi

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
from typing import List, Any, TypeVar
1+
# FIXME: Stub incomplete, ommissions include:
2+
# * the metaclass
3+
# * _sunder_ methods with their transformations
4+
5+
import sys
6+
from typing import List, Any, TypeVar, Union
27

38
class Enum:
49
def __new__(cls, value: Any) -> None: ...
@@ -18,3 +23,28 @@ class IntEnum(int, Enum):
1823
_T = TypeVar('_T')
1924

2025
def unique(enumeration: _T) -> _T: ...
26+
27+
if sys.version_info >= (3, 6):
28+
_auto_null = ... # type: Any
29+
30+
class auto:
31+
value = ... # type: Any
32+
33+
class Flag(Enum):
34+
def __contains__(self: _T, other: _T) -> bool: ...
35+
def __repr__(self) -> str: ...
36+
def __str__(self) -> str: ...
37+
def __bool__(self) -> bool: ...
38+
def __or__(self: _T, other: _T) -> _T: ...
39+
def __and__(self: _T, other: _T) -> _T: ...
40+
def __xor__(self: _T, other: _T) -> _T: ...
41+
def __invert__(self: _T) -> _T: ...
42+
43+
# All `type: ignore` comments below due to IntFlag making the function signatures more permissive.
44+
class IntFlag(int, Flag): # type: ignore
45+
def __or__(self: _T, other: Union[int, _T]) -> _T: ... # type: ignore
46+
def __and__(self: _T, other: Union[int, _T]) -> _T: ... # type: ignore
47+
def __xor__(self: _T, other: Union[int, _T]) -> _T: ... # type: ignore
48+
__ror__ = __or__
49+
__rand__ = __and__
50+
__rxor__ = __xor__

0 commit comments

Comments
 (0)