Skip to content

Commit 4659cd7

Browse files
anandoleecopybara-github
authored andcommitted
Raise warnings for float_precision from python json_format.
Raise warnings for float_format/double_format from python text_format. Those will turn into error in 34.0 release. PiperOrigin-RevId: 791826874
1 parent 3811438 commit 4659cd7

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

python/google/protobuf/json_format.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import math
2727
from operator import methodcaller
2828
import re
29+
import warnings
2930

3031
from google.protobuf import descriptor
3132
from google.protobuf import message_factory
@@ -191,6 +192,11 @@ def __init__(
191192
self.use_integers_for_enums = use_integers_for_enums
192193
self.descriptor_pool = descriptor_pool
193194
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+
)
194200
self.float_format = '.{}g'.format(float_precision)
195201
else:
196202
self.float_format = None

python/google/protobuf/text_format.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io
2626
import math
2727
import re
28+
import warnings
2829

2930
from google.protobuf.internal import decoder
3031
from google.protobuf.internal import type_checkers
@@ -416,6 +417,10 @@ def __init__(
416417
self.use_index_order = use_index_order
417418
self.float_format = float_format
418419
if double_format is not None:
420+
warnings.warn(
421+
'double_format is deprecated for text_format. This will '
422+
'turn into error in 7.34.0, please remove it before that.'
423+
)
419424
self.double_format = double_format
420425
else:
421426
self.double_format = float_format
@@ -652,6 +657,11 @@ def PrintFieldValue(self, field, value):
652657
out.write('false')
653658
elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_FLOAT:
654659
if self.float_format is not None:
660+
warnings.warn(
661+
'float_format is deprecated for text_format. This '
662+
'will turn into error in 7.34.0, please remove it '
663+
'before that.'
664+
)
655665
out.write('{1:{0}}'.format(self.float_format, value))
656666
else:
657667
if math.isnan(value):

0 commit comments

Comments
 (0)