Skip to content

Commit e919d47

Browse files
authored
Improve the test_constructor_proto3 test to show the access behavior (#655)
1 parent 43f9e45 commit e919d47

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

test/test_generated_mypy.py

+5
Original file line numberDiff line numberDiff line change
@@ -426,14 +426,19 @@ def test_constructor_proto3() -> None:
426426
# an_optional_string has optional keyword so None is allowed
427427
x = SimpleProto3(an_optional_string=None)
428428
assert not x.HasField("an_optional_string")
429+
# Field access still returns the 0-value, even though
430+
# the field is not present.
431+
assert x.an_optional_string == ""
429432

430433
x = SimpleProto3(a_string="", an_optional_string="")
431434
assert x.a_string == ""
432435
assert x.HasField("an_optional_string")
436+
assert x.an_optional_string == ""
433437

434438
x = SimpleProto3(a_string="hello", an_optional_string="hello")
435439
assert x.a_string == "hello"
436440
assert x.HasField("an_optional_string")
441+
assert x.an_optional_string == "hello"
437442

438443

439444
def test_message_descriptor_proto2() -> None:

0 commit comments

Comments
 (0)