Skip to content

Commit

Permalink
Add t property to SumType
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-q committed May 9, 2024
1 parent f3d8bcc commit 1d09946
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions hugr-py/src/hugr/serialization/tys.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,12 @@ class GeneralSum(ConfiguredBaseModel):


class SumType(RootModel):
root: Union[UnitSum, GeneralSum] = Field(discriminator="s")
root: Annotated[Union[UnitSum, GeneralSum], Field(discriminator="s")]

# This seems to be required for nested discriminated unions to work
@property
def t(self) -> str:
return self.root.t

class Config:
json_schema_extra = {"required": ["s"]}
Expand Down Expand Up @@ -318,7 +323,8 @@ class Type(RootModel):
root: Annotated[
Qubit | Variable | USize | FunctionType | Array | SumType | Opaque | Alias,
WrapValidator(_json_custom_error_validator),
] = Field(discriminator="t")
Field(discriminator="t"),
]

class Config:
json_schema_extra = {"required": ["t"]}
Expand Down

0 comments on commit 1d09946

Please sign in to comment.