mirror of
https://github.com/protocolbuffers/protobuf
synced 2026-08-26 02:23:14 -04:00
Document Python & PHP non-conformance where booleans are accepted by int and float fields.
PiperOrigin-RevId: 952905948
This commit is contained in:
parent
6a31b747f2
commit
cb440834fd
6 changed files with 56 additions and 0 deletions
|
|
@ -1982,6 +1982,16 @@ class JsonFormatTest(JsonFormatBase):
|
|||
{'armor': 1},
|
||||
)
|
||||
|
||||
def testParseBooleanInputForEnum(self):
|
||||
# In Python, bool is a subclass of int (int(True) == 1). We document that
|
||||
# JSON boolean literals like 'true' are accepted for enum fields and coerced
|
||||
# to integer enum values.
|
||||
msg = json_enumval_custom_string_pb2.Knight()
|
||||
json_format.Parse('{"armor": true}', msg)
|
||||
self.assertEqual(
|
||||
msg.armor, json_enumval_custom_string_pb2.Armor.ARMOR_GREAT_HELM
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue