@@ -573,13 +573,6 @@ def _internal_class_schema(
573
573
return cast (Type [marshmallow .Schema ], schema_class )
574
574
575
575
576
- def _field_by_type (typ : Union [type , Any ]) -> Optional [Type [marshmallow .fields .Field ]]:
577
- # FIXME: remove this function
578
- schema_ctx = _schema_ctx_stack .top
579
- type_mapping = schema_ctx .get_type_mapping (include_marshmallow_default = True )
580
- return type_mapping .get (typ )
581
-
582
-
583
576
def _field_by_supertype (
584
577
typ : Type ,
585
578
default : Any ,
@@ -787,9 +780,12 @@ def _field_for_schema(
787
780
# Generic types specified without type arguments
788
781
typ = _generic_type_add_any (typ )
789
782
783
+ schema_ctx = _schema_ctx_stack .top
784
+
790
785
# Base types
791
- field = _field_by_type (typ )
792
- if field :
786
+ type_mapping = schema_ctx .get_type_mapping (include_marshmallow_default = True )
787
+ field = type_mapping .get (typ )
788
+ if field is not None :
793
789
return field (** metadata )
794
790
795
791
if typ is Any :
@@ -874,12 +870,13 @@ def _field_for_schema(
874
870
# Nested dataclasses
875
871
forward_reference = getattr (typ , "__forward_arg__" , None )
876
872
877
- base_schema = _schema_ctx_stack .top .base_schema
878
873
nested = (
879
874
nested_schema
880
875
or forward_reference
881
- or _schema_ctx_stack .top .seen_classes .get (typ )
882
- or _internal_class_schema (typ , base_schema ) # type: ignore[arg-type] # FIXME
876
+ or schema_ctx .seen_classes .get (typ )
877
+ or _internal_class_schema (
878
+ typ , schema_ctx .base_schema # type: ignore[arg-type] # FIXME
879
+ )
883
880
)
884
881
885
882
return marshmallow .fields .Nested (nested , ** metadata )
0 commit comments