Skip to content

Commit f5cadbd

Browse files
committed
refactor: delete _field_by_type
1 parent 01c71da commit f5cadbd

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

marshmallow_dataclass/__init__.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -552,13 +552,6 @@ def _internal_class_schema(
552552
return cast(Type[marshmallow.Schema], schema_class)
553553

554554

555-
def _field_by_type(typ: Union[type, Any]) -> Optional[Type[marshmallow.fields.Field]]:
556-
# FIXME: remove this function
557-
schema_ctx = _schema_ctx_stack.top
558-
type_mapping = schema_ctx.get_type_mapping(use_mro=True)
559-
return type_mapping.get(typ)
560-
561-
562555
def _field_by_supertype(
563556
typ: Type,
564557
default: Any,
@@ -769,9 +762,12 @@ def _field_for_schema(
769762
# Generic types specified without type arguments
770763
typ = _generic_type_add_any(typ)
771764

765+
schema_ctx = _schema_ctx_stack.top
766+
772767
# Base types
773-
field = _field_by_type(typ)
774-
if field:
768+
type_mapping = schema_ctx.get_type_mapping(use_mro=True)
769+
field = type_mapping.get(typ)
770+
if field is not None:
775771
return field(**metadata)
776772

777773
if typ is Any:
@@ -856,12 +852,13 @@ def _field_for_schema(
856852
# Nested dataclasses
857853
forward_reference = getattr(typ, "__forward_arg__", None)
858854

859-
base_schema = _schema_ctx_stack.top.base_schema
860855
nested = (
861856
nested_schema
862857
or forward_reference
863-
or _schema_ctx_stack.top.seen_classes.get(typ)
864-
or _internal_class_schema(typ, base_schema) # type: ignore[arg-type] # FIXME
858+
or schema_ctx.seen_classes.get(typ)
859+
or _internal_class_schema(
860+
typ, schema_ctx.base_schema # type: ignore[arg-type] # FIXME
861+
)
865862
)
866863

867864
return marshmallow.fields.Nested(nested, **metadata)

0 commit comments

Comments
 (0)