From e54ad600564965b9e1084963cc8fc02a3d3e69c1 Mon Sep 17 00:00:00 2001 From: Jarkko Jaakola Date: Wed, 16 Oct 2024 13:46:54 +0300 Subject: [PATCH] fix: Avro dataclass introspect typing --- src/karapace/avro_dataclasses/introspect.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/karapace/avro_dataclasses/introspect.py b/src/karapace/avro_dataclasses/introspect.py index be9634493..7ba38ab00 100644 --- a/src/karapace/avro_dataclasses/introspect.py +++ b/src/karapace/avro_dataclasses/introspect.py @@ -42,10 +42,17 @@ def _field_type_array(field: Field, origin: type, type_: object) -> AvroType: else: (inner_type,) = get_args(type_) + items: AvroType + if is_dataclass(inner_type): + assert isinstance(inner_type, type) + items = record_schema(inner_type) + else: + items = _field_type(field, inner_type) + return { "name": f"one_of_{field.name}", "type": "array", - "items": (record_schema(inner_type) if is_dataclass(inner_type) else _field_type(field, inner_type)), + "items": items, } @@ -128,7 +135,7 @@ def _field_type(field: Field, type_: object) -> AvroType: # pylint: disable=too T = TypeVar("T", str, int, bool, Enum, None) -def transform_default(type_: type[T], default: T) -> str | int | bool | None: +def transform_default(type_: type[T] | str, default: T) -> str | int | bool | None: if isinstance(default, Enum): assert isinstance(type_, type) assert issubclass(type_, Enum)