Skip to content
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

fix: schema for array inner types #1494

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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
Loading