Skip to content

Commit

Permalink
Typing fixes for mypy 1.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Mátyás Kuti committed Dec 1, 2023
1 parent e58fd14 commit 2b29ada
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
31 changes: 15 additions & 16 deletions karapace/avro_dataclasses/introspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 "
Expand Down
1 change: 0 additions & 1 deletion karapace/avro_dataclasses/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class EnumType(TypedDict):


class MapType(TypedDict):
name: str
type: Literal["map"]
values: AvroType
default: NotRequired[Mapping[str, AvroType]]
Expand Down
1 change: 0 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2b29ada

Please sign in to comment.