From d43cbb2c3035f49e4ea7a7769fd1a51db31806ce Mon Sep 17 00:00:00 2001 From: Seyon Sivarajah Date: Fri, 30 Aug 2024 16:27:59 +0100 Subject: [PATCH] fix: schema for array inner types (#1494) Closes #1471 --- hugr-py/src/hugr/_serialization/tys.py | 9 +++------ hugr-py/src/hugr/tys.py | 2 +- specification/schema/hugr_schema_live.json | 8 ++++---- specification/schema/hugr_schema_strict_live.json | 8 ++++---- specification/schema/testing_hugr_schema_live.json | 8 ++++---- .../schema/testing_hugr_schema_strict_live.json | 8 ++++---- 6 files changed, 20 insertions(+), 23 deletions(-) diff --git a/hugr-py/src/hugr/_serialization/tys.py b/hugr-py/src/hugr/_serialization/tys.py index eff523560..452816bf5 100644 --- a/hugr-py/src/hugr/_serialization/tys.py +++ b/hugr-py/src/hugr/_serialization/tys.py @@ -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): diff --git a/hugr-py/src/hugr/tys.py b/hugr-py/src/hugr/tys.py index fb273ece4..7c13e50b9 100644 --- a/hugr-py/src/hugr/tys.py +++ b/hugr-py/src/hugr/tys.py @@ -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() diff --git a/specification/schema/hugr_schema_live.json b/specification/schema/hugr_schema_live.json index 4a8c48df6..26c2f3bfc 100644 --- a/specification/schema/hugr_schema_live.json +++ b/specification/schema/hugr_schema_live.json @@ -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", @@ -108,13 +105,16 @@ "title": "T", "type": "string" }, + "inner": { + "$ref": "#/$defs/Type" + }, "len": { "title": "Len", "type": "integer" } }, "required": [ - "ty", + "inner", "len" ], "title": "Array", diff --git a/specification/schema/hugr_schema_strict_live.json b/specification/schema/hugr_schema_strict_live.json index d153e7e98..3ae0e3c28 100644 --- a/specification/schema/hugr_schema_strict_live.json +++ b/specification/schema/hugr_schema_strict_live.json @@ -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", @@ -108,13 +105,16 @@ "title": "T", "type": "string" }, + "inner": { + "$ref": "#/$defs/Type" + }, "len": { "title": "Len", "type": "integer" } }, "required": [ - "ty", + "inner", "len" ], "title": "Array", diff --git a/specification/schema/testing_hugr_schema_live.json b/specification/schema/testing_hugr_schema_live.json index eb2c9c4ef..7696790dc 100644 --- a/specification/schema/testing_hugr_schema_live.json +++ b/specification/schema/testing_hugr_schema_live.json @@ -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", @@ -108,13 +105,16 @@ "title": "T", "type": "string" }, + "inner": { + "$ref": "#/$defs/Type" + }, "len": { "title": "Len", "type": "integer" } }, "required": [ - "ty", + "inner", "len" ], "title": "Array", diff --git a/specification/schema/testing_hugr_schema_strict_live.json b/specification/schema/testing_hugr_schema_strict_live.json index 85297e69d..0490b157d 100644 --- a/specification/schema/testing_hugr_schema_strict_live.json +++ b/specification/schema/testing_hugr_schema_strict_live.json @@ -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", @@ -108,13 +105,16 @@ "title": "T", "type": "string" }, + "inner": { + "$ref": "#/$defs/Type" + }, "len": { "title": "Len", "type": "integer" } }, "required": [ - "ty", + "inner", "len" ], "title": "Array",