2626import math
2727from operator import methodcaller
2828import re
29- import warnings
3029
3130from google .protobuf import descriptor
3231from google .protobuf import message_factory
@@ -85,7 +84,6 @@ def MessageToJson(
8584 sort_keys = False ,
8685 use_integers_for_enums = False ,
8786 descriptor_pool = None ,
88- float_precision = None ,
8987 ensure_ascii = True ,
9088 always_print_fields_with_no_presence = False ,
9189):
@@ -107,8 +105,6 @@ def MessageToJson(
107105 use_integers_for_enums: If true, print integers instead of enum names.
108106 descriptor_pool: A Descriptor Pool for resolving types. If None use the
109107 default.
110- float_precision: Deprecated. If set, use this to specify float field valid
111- digits.
112108 ensure_ascii: If True, strings with non-ASCII characters are escaped. If
113109 False, Unicode strings are returned unchanged.
114110
@@ -119,7 +115,6 @@ def MessageToJson(
119115 preserving_proto_field_name ,
120116 use_integers_for_enums ,
121117 descriptor_pool ,
122- float_precision ,
123118 always_print_fields_with_no_presence ,
124119 )
125120 return printer .ToJsonString (message , indent , sort_keys , ensure_ascii )
@@ -131,7 +126,6 @@ def MessageToDict(
131126 preserving_proto_field_name = False ,
132127 use_integers_for_enums = False ,
133128 descriptor_pool = None ,
134- float_precision = None ,
135129):
136130 """Converts protobuf message to a dictionary.
137131
@@ -149,8 +143,6 @@ def MessageToDict(
149143 use_integers_for_enums: If true, print integers instead of enum names.
150144 descriptor_pool: A Descriptor Pool for resolving types. If None use the
151145 default.
152- float_precision: Deprecated. If set, use this to specify float field valid
153- digits.
154146
155147 Returns:
156148 A dict representation of the protocol buffer message.
@@ -159,7 +151,6 @@ def MessageToDict(
159151 preserving_proto_field_name ,
160152 use_integers_for_enums ,
161153 descriptor_pool ,
162- float_precision ,
163154 always_print_fields_with_no_presence ,
164155 )
165156 # pylint: disable=protected-access
@@ -182,7 +173,6 @@ def __init__(
182173 preserving_proto_field_name = False ,
183174 use_integers_for_enums = False ,
184175 descriptor_pool = None ,
185- float_precision = None ,
186176 always_print_fields_with_no_presence = False ,
187177 ):
188178 self .always_print_fields_with_no_presence = (
@@ -191,15 +181,6 @@ def __init__(
191181 self .preserving_proto_field_name = preserving_proto_field_name
192182 self .use_integers_for_enums = use_integers_for_enums
193183 self .descriptor_pool = descriptor_pool
194- if float_precision :
195- warnings .warn (
196- 'float_precision option is deprecated for json_format. '
197- 'This will turn into error in 7.34.0, please remove it '
198- 'before that.'
199- )
200- self .float_format = '.{}g' .format (float_precision )
201- else :
202- self .float_format = None
203184
204185 def ToJsonString (self , message , indent , sort_keys , ensure_ascii ):
205186 js = self ._MessageToJsonObject (message )
@@ -322,8 +303,6 @@ def _FieldToJsonObject(self, field, value):
322303 return _INFINITY
323304 if math .isnan (value ):
324305 return _NAN
325- if self .float_format :
326- return float (format (value , self .float_format ))
327306 elif field .cpp_type == descriptor .FieldDescriptor .CPPTYPE_FLOAT :
328307 return type_checkers .ToShortestFloat (value )
329308
0 commit comments