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 c43b259
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
32 changes: 16 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,14 @@ 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 = {
"name": field.name,
"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 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 c43b259

Please sign in to comment.