[ty] enum.Flag

This commit is contained in:
David Peter 2025-07-29 16:52:42 +02:00
parent 81867ea7ce
commit e935bc5578
1 changed files with 16 additions and 0 deletions

View File

@ -559,6 +559,22 @@ class Answer(Enum):
reveal_type(enum_members(Answer))
```
## Subclasses of `enum.Flag`
```py
from enum import Flag, auto
class KeyModifier(Flag):
SHIFT = auto()
CTRL = auto()
ALT = auto()
reveal_type(KeyModifier.SHIFT) # revealed: Literal[KeyModifier.SHIFT]
# TODO: this should be `KeyModifier`
reveal_type(KeyModifier.SHIFT | KeyModifier.CTRL) # revealed: Literal[KeyModifier.CTRL]
```
## Custom enum types
Enum classes can also be defined using a subclass of `enum.Enum` or any class that uses