Skip to content

Commit

Permalink
fix schema for array inner types
Browse files Browse the repository at this point in the history
  • Loading branch information
ss2165 committed Aug 30, 2024
1 parent 26ec57a commit bde0b3f
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)

Check warning on line 235 in hugr-py/src/hugr/_serialization/tys.py

View check run for this annotation

Codecov / codecov/patch

hugr-py/src/hugr/_serialization/tys.py#L235

Added line #L235 was not covered by tests


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)

Check warning on line 271 in hugr-py/src/hugr/tys.py

View check run for this annotation

Codecov / codecov/patch

hugr-py/src/hugr/tys.py#L271

Added line #L271 was not covered by tests

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 bde0b3f

Please sign in to comment.