Skip to content

Commit

Permalink
fix: schema for array inner types (#1494)
Browse files Browse the repository at this point in the history
Closes #1471
  • Loading branch information
ss2165 authored Aug 30, 2024
1 parent 26ec57a commit d43cbb2
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 23 deletions.
9 changes: 3 additions & 6 deletions hugr-py/src/hugr/_serialization/tys.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,15 @@ class BaseType(ABC, ConfiguredBaseModel):
def deserialize(self) -> tys.Type: ...


class MultiContainer(BaseType):
ty: Type


class Array(MultiContainer):
class Array(BaseType):
"""Known size array whose elements are of the same type."""

t: Literal["Array"] = "Array"
inner: Type
len: int

def deserialize(self) -> tys.Array:
return tys.Array(ty=self.ty.deserialize(), size=self.len)
return tys.Array(ty=self.inner.deserialize(), size=self.len)


class UnitSum(BaseType):
Expand Down
2 changes: 1 addition & 1 deletion hugr-py/src/hugr/tys.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class Array(Type):
size: int

def _to_serial(self) -> stys.Array:
return stys.Array(ty=self.ty._to_serial_root(), len=self.size)
return stys.Array(inner=self.ty._to_serial_root(), len=self.size)

def type_bound(self) -> TypeBound:
return self.ty.type_bound()
Expand Down
8 changes: 4 additions & 4 deletions specification/schema/hugr_schema_live.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@
"additionalProperties": true,
"description": "Known size array whose elements are of the same type.",
"properties": {
"ty": {
"$ref": "#/$defs/Type"
},
"t": {
"const": "Array",
"default": "Array",
Expand All @@ -108,13 +105,16 @@
"title": "T",
"type": "string"
},
"inner": {
"$ref": "#/$defs/Type"
},
"len": {
"title": "Len",
"type": "integer"
}
},
"required": [
"ty",
"inner",
"len"
],
"title": "Array",
Expand Down
8 changes: 4 additions & 4 deletions specification/schema/hugr_schema_strict_live.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@
"additionalProperties": false,
"description": "Known size array whose elements are of the same type.",
"properties": {
"ty": {
"$ref": "#/$defs/Type"
},
"t": {
"const": "Array",
"default": "Array",
Expand All @@ -108,13 +105,16 @@
"title": "T",
"type": "string"
},
"inner": {
"$ref": "#/$defs/Type"
},
"len": {
"title": "Len",
"type": "integer"
}
},
"required": [
"ty",
"inner",
"len"
],
"title": "Array",
Expand Down
8 changes: 4 additions & 4 deletions specification/schema/testing_hugr_schema_live.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@
"additionalProperties": true,
"description": "Known size array whose elements are of the same type.",
"properties": {
"ty": {
"$ref": "#/$defs/Type"
},
"t": {
"const": "Array",
"default": "Array",
Expand All @@ -108,13 +105,16 @@
"title": "T",
"type": "string"
},
"inner": {
"$ref": "#/$defs/Type"
},
"len": {
"title": "Len",
"type": "integer"
}
},
"required": [
"ty",
"inner",
"len"
],
"title": "Array",
Expand Down
8 changes: 4 additions & 4 deletions specification/schema/testing_hugr_schema_strict_live.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@
"additionalProperties": false,
"description": "Known size array whose elements are of the same type.",
"properties": {
"ty": {
"$ref": "#/$defs/Type"
},
"t": {
"const": "Array",
"default": "Array",
Expand All @@ -108,13 +105,16 @@
"title": "T",
"type": "string"
},
"inner": {
"$ref": "#/$defs/Type"
},
"len": {
"title": "Len",
"type": "integer"
}
},
"required": [
"ty",
"inner",
"len"
],
"title": "Array",
Expand Down

0 comments on commit d43cbb2

Please sign in to comment.