-
Notifications
You must be signed in to change notification settings - Fork 259
feat(enum): add Enum type engine+python #1218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| Str, | ||
|
|
||
| /// Enumerated symbolic value. | ||
| Enum, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should keep a bunch of allowed enum values here (as strings). The information is needed to create JSON schema, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Variants are field-specific, so I stored them.
JSON Schema already reads this and emits "enum".
I can add a typed accessor EnrichedValueType::enum_variants() and a ENUM_VARIANTS_ATTR const to avoid magic strings.
If you’d rather model it as BasicValueType::Enum { variants: Option<Vec<String>> }, happy to refactor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Thanks for the explanation.
I think putting it into BasicValueType is better than using attributes. Attributes are not part of the value type - more like some additional annotations. In most type systems, enum variants is part of the type (similar to variants of union type).
think we should go with BasicValueType::Enum(EnumTypeSchema), and EnumTypeSchema has a variants: Vec<Arc<str>> member.
| Str, | ||
|
|
||
| /// Enumerated symbolic value. | ||
| Enum, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Thanks for the explanation.
I think putting it into BasicValueType is better than using attributes. Attributes are not part of the value type - more like some additional annotations. In most type systems, enum variants is part of the type (similar to variants of union type).
think we should go with BasicValueType::Enum(EnumTypeSchema), and EnumTypeSchema has a variants: Vec<Arc<str>> member.
| def Enum(*, variants: Optional[Sequence[str]] = None) -> Any: | ||
| """ | ||
| String-like enumerated type. Use `variants` to hint allowed values. | ||
| Example: | ||
| color: Enum(variants=["red", "green", "blue"]) | ||
| At runtime this is a plain `str`; `variants` are emitted as schema attrs. | ||
| """ | ||
| if variants is not None: | ||
| return Annotated[str, TypeKind("Enum"), TypeAttr("variants", list(variants))] | ||
| return Annotated[str, TypeKind("Enum")] | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably don't need this. Users can directly use Python's native way to represent enums, similar to union type.
Implements Enum basic type in engine + Python SDK, adds variants attr; updates JSON Schema and docs. Tests & pre-commit pass. Related: #523