Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions python/google/protobuf/json_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import math
from operator import methodcaller
import re
import warnings

from google.protobuf import descriptor
from google.protobuf import message_factory
Expand Down Expand Up @@ -191,6 +192,11 @@ def __init__(
self.use_integers_for_enums = use_integers_for_enums
self.descriptor_pool = descriptor_pool
if float_precision:
warnings.warn(
'float_precision option is deprecated for json_format. '
'This will turn into error in 7.34.0, please remove it '
'before that.'
)
self.float_format = '.{}g'.format(float_precision)
else:
self.float_format = None
Expand Down
10 changes: 10 additions & 0 deletions python/google/protobuf/text_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io
import math
import re
import warnings

from google.protobuf.internal import decoder
from google.protobuf.internal import type_checkers
Expand Down Expand Up @@ -416,6 +417,10 @@ def __init__(
self.use_index_order = use_index_order
self.float_format = float_format
if double_format is not None:
warnings.warn(
'double_format is deprecated for text_format. This will '
'turn into error in 7.34.0, please remove it before that.'
)
self.double_format = double_format
else:
self.double_format = float_format
Expand Down Expand Up @@ -652,6 +657,11 @@ def PrintFieldValue(self, field, value):
out.write('false')
elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_FLOAT:
if self.float_format is not None:
warnings.warn(
'float_format is deprecated for text_format. This '
'will turn into error in 7.34.0, please remove it '
'before that.'
)
out.write('{1:{0}}'.format(self.float_format, value))
else:
if math.isnan(value):
Expand Down
Loading