This commit is contained in:
David Peter 2025-12-17 04:19:51 +11:00 committed by GitHub
commit df4cf3ef9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 0 deletions

View File

@ -771,6 +771,22 @@ class Answer(Enum):
reveal_type(enum_members(Answer)) 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 ## Custom enum types
Enum classes can also be defined using a subclass of `enum.Enum` or any class that uses Enum classes can also be defined using a subclass of `enum.Enum` or any class that uses