@@ -785,7 +785,7 @@ def __init__(self, cls: Type["Message"]):
785
785
def _get_default_gen (
786
786
cls : Type ["Message" ], fields : Iterable [dataclasses .Field ]
787
787
) -> Dict [str , Callable [[], Any ]]:
788
- return {field .name : cls . _get_field_default_gen ( field ) for field in fields }
788
+ return {field .name : field . default_factory for field in fields }
789
789
790
790
@staticmethod
791
791
def _get_cls_by_field (
@@ -1045,40 +1045,6 @@ def _get_field_default(self, field_name: str) -> Any:
1045
1045
warnings .filterwarnings ("ignore" , category = DeprecationWarning )
1046
1046
return self ._betterproto .default_gen [field_name ]()
1047
1047
1048
- @classmethod
1049
- def _get_field_default_gen (cls , field : dataclasses .Field ) -> Any :
1050
- if field .metadata ["betterproto" ].optional :
1051
- return type (None )
1052
-
1053
- t = cls ._type_hint (field .name )
1054
-
1055
- is_310_union = isinstance (t , _types_UnionType )
1056
- if hasattr (t , "__origin__" ) or is_310_union :
1057
- if is_310_union or t .__origin__ is Union :
1058
- # This is an optional field (either wrapped, or using proto3
1059
- # field presence). For setting the default we really don't care
1060
- # what kind of field it is.
1061
- return type (None )
1062
- if t .__origin__ is list :
1063
- # This is some kind of list (repeated) field.
1064
- return list
1065
- if t .__origin__ is dict :
1066
- # This is some kind of map (dict in Python).
1067
- return dict
1068
- return t
1069
- if issubclass (t , Enum ):
1070
- # Enums always default to zero.
1071
- return t .try_value
1072
- if t is datetime :
1073
- # Offsets are relative to 1970-01-01T00:00:00Z
1074
- return datetime_default_gen
1075
- # In proto 3, message fields are always optional
1076
- if issubclass (t , Message ):
1077
- return type (None )
1078
- # This is either a primitive scalar or another message type. Calling
1079
- # it should result in its zero value.
1080
- return t
1081
-
1082
1048
def _postprocess_single (
1083
1049
self , wire_type : int , meta : FieldMetadata , field_name : str , value : Any
1084
1050
) -> Any :
0 commit comments