Debian Codegraph @

test-data/unit/lib-stub/enum.pyi

raw
1 from typing import Any, TypeVar, Union, Type, Sized, Iterator
2 from typing_extensions import Literal
3
4 _T = TypeVar('_T')
5
6 class EnumMeta(type, Sized):
7 def __len__(self) -> int: pass # to make it non-abstract
8 def __iter__(self: Type[_T]) -> Iterator[_T]: pass
9 def __reversed__(self: Type[_T]) -> Iterator[_T]: pass
10 def __getitem__(self: Type[_T], name: str) -> _T: pass
11 def __bool__(self) -> Literal[True]: pass
12
13 class Enum(metaclass=EnumMeta):
14 def __new__(cls: Type[_T], value: object) -> _T: pass
15 def __repr__(self) -> str: pass
16 def __str__(self) -> str: pass
17 def __format__(self, format_spec: str) -> str: pass
18 def __hash__(self) -> Any: pass
19 def __reduce_ex__(self, proto: Any) -> Any: pass
20
21 name: str
22 value: Any
23 _name_: str
24 _value_: Any
25
26 # In reality, _generate_next_value_ is python3.6 only and has a different signature.
27 # However, this should be quick and doesn't require additional stubs (e.g. `staticmethod`)
28 def _generate_next_value_(self) -> Any: pass
29
30 class IntEnum(int, Enum):
31 value: int
32 _value_: int
33 def __new__(cls: Type[_T], value: Union[int, _T]) -> _T: ...
34
35 def unique(enumeration: _T) -> _T: pass
36
37 # In reality Flag and IntFlag are 3.6 only
38
39 class Flag(Enum):
40 value: int
41 _value_: int
42 def __or__(self: _T, other: Union[int, _T]) -> _T: pass
43
44
45 class IntFlag(int, Flag):
46 def __and__(self: _T, other: Union[int, _T]) -> _T: pass
47
48
49 class auto(IntFlag):
50 value: Any
51
52
53 # It is python-3.11+ only:
54 class StrEnum(str, Enum):
55 _value_: str
56 value: str
57 def __new__(cls: Type[_T], value: str | _T) -> _T: ...
58
59 # It is python-3.11+ only:
60 class nonmember(Generic[_T]):
61 value: _T
62 def __init__(self, value: _T) -> None: ...
63
64 # It is python-3.11+ only:
65 class member(Generic[_T]):
66 value: _T
67 def __init__(self, value: _T) -> None: ...