Skip to content

Commit

Permalink
Merge pull request #976 from Aiven-Open/jjaakola-aiven-fix-avro-datac…
Browse files Browse the repository at this point in the history
…lass-introspect-typing

fix: Avro dataclass introspect typing
  • Loading branch information
keejon authored Oct 16, 2024
2 parents f9f5fe7 + e54ad60 commit 458b1a6
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/karapace/avro_dataclasses/introspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}


Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 458b1a6

Please sign in to comment.