1616
1717from marshmallow import RAISE , fields
1818from marshmallow .exceptions import ValidationError
19- from marshmallow .fields import _T , Field , Nested
19+ from marshmallow .fields import Field , Nested
2020from marshmallow .utils import FieldInstanceResolutionError , from_iso_datetime , resolve_field_instance
2121
2222from ..._utils ._arm_id_utils import AMLVersionedArmId , is_ARM_id_for_resource , parse_name_label , parse_name_version
4444from ..core .schema import PathAwareSchema
4545
4646module_logger = logging .getLogger (__name__ )
47+ T = typing .TypeVar ("T" )
4748
4849
4950class StringTransformedEnum (Field ):
@@ -830,7 +831,7 @@ def _validate(self, value):
830831class DumpableIntegerField (fields .Integer ):
831832 """A int field that cannot serialize other type of values to int if self.strict."""
832833
833- def _serialize (self , value , attr , obj , ** kwargs ) -> typing .Optional [typing .Union [str , _T ]]:
834+ def _serialize (self , value , attr , obj , ** kwargs ) -> typing .Optional [typing .Union [str , T ]]:
834835 if self .strict and not isinstance (value , int ):
835836 # this implementation can serialize bool to bool
836837 raise self .make_error ("invalid" , input = value )
@@ -856,14 +857,14 @@ def _validated(self, value):
856857 raise self .make_error ("invalid" , input = value )
857858 return super ()._validated (value )
858859
859- def _serialize (self , value , attr , obj , ** kwargs ) -> typing .Optional [typing .Union [str , _T ]]:
860+ def _serialize (self , value , attr , obj , ** kwargs ) -> typing .Optional [typing .Union [str , T ]]:
860861 return super ()._serialize (self ._validated (value ), attr , obj , ** kwargs )
861862
862863
863864class DumpableStringField (fields .String ):
864865 """A string field that cannot serialize other type of values to string if self.strict."""
865866
866- def _serialize (self , value , attr , obj , ** kwargs ) -> typing .Optional [typing .Union [str , _T ]]:
867+ def _serialize (self , value , attr , obj , ** kwargs ) -> typing .Optional [typing .Union [str , T ]]:
867868 if not isinstance (value , str ):
868869 raise ValidationError ("Given value is not a string" )
869870 return super ()._serialize (value , attr , obj , ** kwargs )
0 commit comments