diff --git a/karapace/avro_dataclasses/introspect.py b/karapace/avro_dataclasses/introspect.py index 93f3ab9ce..64b2e5856 100644 --- a/karapace/avro_dataclasses/introspect.py +++ b/karapace/avro_dataclasses/introspect.py @@ -98,15 +98,14 @@ def _field_type(field: Field, type_: object) -> AvroType: # pylint: disable=too # Handle enums. if isinstance(type_, type) and issubclass(type_, Enum): - return EnumType( - { - # Conditionally set a default. - **({"default": field.default.value} if field.default is not MISSING else {}), - "name": type_.__name__, - "type": "enum", - "symbols": [value.value for value in type_], - } - ) + enum_dict: EnumType = { + "name": type_.__name__, + "type": "enum", + "symbols": [value.value for value in type_], + } + if field.default is not MISSING: + enum_dict["default"] = field.default.value + return enum_dict # Handle map types. if origin is Mapping: @@ -115,13 +114,13 @@ def _field_type(field: Field, type_: object) -> AvroType: # pylint: disable=too raise UnderspecifiedAnnotation("Key and value types must be specified for map types") if args[0] is not str: raise UnsupportedAnnotation("Key type must be str") - return MapType( - { - "type": "map", - "values": _field_type(field, args[1]), - **({"default": field.default_factory()} if field.default_factory is not MISSING else {}), - } - ) + map_dict: MapType = { + "type": "map", + "values": _field_type(field, args[1]), + } + if field.default_factory is not MISSING: + map_dict["default"] = field.default_factory() + return map_dict raise NotImplementedError( f"Found an unknown type {type_!r} while assembling Avro schema for the field " diff --git a/karapace/avro_dataclasses/schema.py b/karapace/avro_dataclasses/schema.py index fdb524303..b49c1d2c5 100644 --- a/karapace/avro_dataclasses/schema.py +++ b/karapace/avro_dataclasses/schema.py @@ -31,7 +31,6 @@ class EnumType(TypedDict): class MapType(TypedDict): - name: str type: Literal["map"] values: AvroType default: NotRequired[Mapping[str, AvroType]] diff --git a/mypy.ini b/mypy.ini index 38fe8c48a..15ab9042f 100644 --- a/mypy.ini +++ b/mypy.ini @@ -14,7 +14,6 @@ warn_unused_ignores = True warn_no_return = True warn_unreachable = True strict_equality = True -enable_incomplete_feature = Unpack [mypy-karapace.schema_registry_apis] ignore_errors = True diff --git a/requirements/requirements-typing.txt b/requirements/requirements-typing.txt index f757e763a..0b9a4df67 100644 --- a/requirements/requirements-typing.txt +++ b/requirements/requirements-typing.txt @@ -7,25 +7,34 @@ attrs==23.1.0 # via # -c requirements-dev.txt + # -c requirements.txt # referencing certifi==2023.7.22 # via # -c requirements-dev.txt # sentry-sdk -mypy==1.6.1 +mypy==1.7.1 # via -r requirements-typing.in mypy-extensions==1.0.0 # via mypy referencing==0.30.0 # via # -c requirements-dev.txt + # -c requirements.txt # types-jsonschema rpds-py==0.9.2 # via # -c requirements-dev.txt + # -c requirements.txt # referencing sentry-sdk==1.31.0 - # via -r requirements-typing.in + # via + # -c requirements-dev.txt + # -r requirements-typing.in +tomli==2.0.1 + # via + # -c requirements-dev.txt + # mypy types-cachetools==5.3.0.7 # via -r requirements-typing.in types-jsonschema==4.19.0.4 @@ -35,6 +44,7 @@ types-protobuf==3.20.3 typing-extensions==4.6.3 # via # -c requirements-dev.txt + # -c requirements.txt # mypy urllib3==2.0.7 # via