@@ -394,7 +394,10 @@ def _internal_class_schema(
394394 clazz_frame : Optional [types .FrameType ] = None ,
395395 generic_params_to_args : Optional [Tuple [Tuple [type , type ], ...]] = None ,
396396) -> Type [marshmallow .Schema ]:
397- _RECURSION_GUARD .seen_classes [clazz ] = clazz .__name__
397+ # generic aliases do not have a __name__ prior python 3.10
398+ _name = getattr (clazz , "__name__" , repr (clazz ))
399+
400+ _RECURSION_GUARD .seen_classes [clazz ] = _name
398401 try :
399402 fields = _dataclass_fields (clazz )
400403 except TypeError : # Not a dataclass
@@ -450,7 +453,7 @@ def _internal_class_schema(
450453 if field .init or include_non_init
451454 )
452455
453- schema_class = type (clazz . __name__ , (_base_schema (clazz , base_schema ),), attributes )
456+ schema_class = type (_name , (_base_schema (clazz , base_schema ),), attributes )
454457 return cast (Type [marshmallow .Schema ], schema_class )
455458
456459
@@ -469,6 +472,7 @@ def _field_by_supertype(
469472 metadata : dict ,
470473 base_schema : Optional [Type [marshmallow .Schema ]],
471474 typ_frame : Optional [types .FrameType ],
475+ generic_params_to_args : Optional [Tuple [Tuple [type , type ], ...]] = None ,
472476) -> marshmallow .fields .Field :
473477 """
474478 Return a new field for fields based on a super field. (Usually spawned from NewType)
@@ -500,6 +504,7 @@ def _field_by_supertype(
500504 default = default ,
501505 base_schema = base_schema ,
502506 typ_frame = typ_frame ,
507+ generic_params_to_args = generic_params_to_args ,
503508 )
504509
505510
@@ -524,6 +529,7 @@ def _field_for_generic_type(
524529 typ : type ,
525530 base_schema : Optional [Type [marshmallow .Schema ]],
526531 typ_frame : Optional [types .FrameType ],
532+ generic_params_to_args : Optional [Tuple [Tuple [type , type ], ...]] = None ,
527533 ** metadata : Any ,
528534) -> Optional [marshmallow .fields .Field ]:
529535 """
@@ -537,7 +543,10 @@ def _field_for_generic_type(
537543
538544 if origin in (list , List ):
539545 child_type = field_for_schema (
540- arguments [0 ], base_schema = base_schema , typ_frame = typ_frame
546+ arguments [0 ],
547+ base_schema = base_schema ,
548+ typ_frame = typ_frame ,
549+ generic_params_to_args = generic_params_to_args ,
541550 )
542551 list_type = cast (
543552 Type [marshmallow .fields .List ],
@@ -552,14 +561,20 @@ def _field_for_generic_type(
552561 from . import collection_field
553562
554563 child_type = field_for_schema (
555- arguments [0 ], base_schema = base_schema , typ_frame = typ_frame
564+ arguments [0 ],
565+ base_schema = base_schema ,
566+ typ_frame = typ_frame ,
567+ generic_params_to_args = generic_params_to_args ,
556568 )
557569 return collection_field .Sequence (cls_or_instance = child_type , ** metadata )
558570 if origin in (set , Set ):
559571 from . import collection_field
560572
561573 child_type = field_for_schema (
562- arguments [0 ], base_schema = base_schema , typ_frame = typ_frame
574+ arguments [0 ],
575+ base_schema = base_schema ,
576+ typ_frame = typ_frame ,
577+ generic_params_to_args = generic_params_to_args ,
563578 )
564579 return collection_field .Set (
565580 cls_or_instance = child_type , frozen = False , ** metadata
@@ -568,14 +583,22 @@ def _field_for_generic_type(
568583 from . import collection_field
569584
570585 child_type = field_for_schema (
571- arguments [0 ], base_schema = base_schema , typ_frame = typ_frame
586+ arguments [0 ],
587+ base_schema = base_schema ,
588+ typ_frame = typ_frame ,
589+ generic_params_to_args = generic_params_to_args ,
572590 )
573591 return collection_field .Set (
574592 cls_or_instance = child_type , frozen = True , ** metadata
575593 )
576594 if origin in (tuple , Tuple ):
577595 children = tuple (
578- field_for_schema (arg , base_schema = base_schema , typ_frame = typ_frame )
596+ field_for_schema (
597+ arg ,
598+ base_schema = base_schema ,
599+ typ_frame = typ_frame ,
600+ generic_params_to_args = generic_params_to_args ,
601+ )
579602 for arg in arguments
580603 )
581604 tuple_type = cast (
@@ -589,10 +612,16 @@ def _field_for_generic_type(
589612 dict_type = type_mapping .get (Dict , marshmallow .fields .Dict )
590613 return dict_type (
591614 keys = field_for_schema (
592- arguments [0 ], base_schema = base_schema , typ_frame = typ_frame
615+ arguments [0 ],
616+ base_schema = base_schema ,
617+ typ_frame = typ_frame ,
618+ generic_params_to_args = generic_params_to_args ,
593619 ),
594620 values = field_for_schema (
595- arguments [1 ], base_schema = base_schema , typ_frame = typ_frame
621+ arguments [1 ],
622+ base_schema = base_schema ,
623+ typ_frame = typ_frame ,
624+ generic_params_to_args = generic_params_to_args ,
596625 ),
597626 ** metadata ,
598627 )
@@ -610,6 +639,7 @@ def _field_for_generic_type(
610639 metadata = metadata ,
611640 base_schema = base_schema ,
612641 typ_frame = typ_frame ,
642+ generic_params_to_args = generic_params_to_args ,
613643 )
614644 from . import union_field
615645
@@ -622,6 +652,7 @@ def _field_for_generic_type(
622652 metadata = {"required" : True },
623653 base_schema = base_schema ,
624654 typ_frame = typ_frame ,
655+ generic_params_to_args = generic_params_to_args ,
625656 ),
626657 )
627658 for subtyp in subtypes
@@ -730,7 +761,9 @@ def field_for_schema(
730761 )
731762 else :
732763 subtyp = Any
733- return field_for_schema (subtyp , default , metadata , base_schema , typ_frame )
764+ return field_for_schema (
765+ subtyp , default , metadata , base_schema , typ_frame , generic_params_to_args
766+ )
734767
735768 # Generic types
736769 generic_field = _field_for_generic_type (typ , base_schema , typ_frame , ** metadata )
@@ -748,6 +781,7 @@ def field_for_schema(
748781 metadata = metadata ,
749782 base_schema = base_schema ,
750783 typ_frame = typ_frame ,
784+ generic_params_to_args = generic_params_to_args ,
751785 )
752786
753787 # enumerations
0 commit comments