Enum attribute
enum_attribute
¶
EnumType = TypeVar('EnumType', bound=StrEnum)
module-attribute
¶
EnumAttribute
dataclass
¶
Helper for Enum Attributes. Takes a StrEnum type parameter, and defines parsing/printing automatically from its values, restricted to be parsable as identifiers.
example:
class MyEnum(StrEnum):
First = auto()
Second = auto()
class MyEnumAttribute(EnumAttribute[MyEnum], SpacedOpaqueSyntaxAttribute):
name = "example.my_enum"
example<my_enum first> and example<my_enum second>
Source code in xdsl/dialects/utils/enum_attribute.py
enum_type: type[StrEnum]
class-attribute
¶
__init_subclass__() -> None
¶
Extract and store the Enum type used by the subclass for use in parsing/printing.
Subclass implementations are also constrained to keep implementations reasonable, unless more complex use cases appear.
The constraint(s) are: - Only direct, specialized inheritance is allowed. That is, using a subclass of EnumAttribute as a base class is not supported. This simplifies type-hacking code and I don't see it being too restrictive anytime soon.