Skip to content

Conversation

@MrAnayDongre
Copy link
Contributor

Implements Enum basic type in engine + Python SDK, adds variants attr; updates JSON Schema and docs. Tests & pre-commit pass. Related: #523

Str,

/// Enumerated symbolic value.
Enum,
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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,
Copy link
Member

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.

Comment on lines +70 to +81
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")]


Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants