Skip to content

Commit 1cffd8d

Browse files
authored
fix: add additional reserved names for disambiguation (googleapis#1114)
The monikers "mapping" and "ignore_unknown_fields" have reserved meaning in the constructor of proto.Message and therefore any fields with those names need disambiguation.
1 parent cafcbfb commit 1cffd8d

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

gapic/utils/reserved_names.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,8 @@
2525
keyword.kwlist,
2626
# We make SOME exceptions for certain names that collide with builtins.
2727
set(dir(builtins)) - {"filter", "map", "id", "input", "property"},
28+
# "mapping" and "ignore_unknown_fields" have special uses
29+
# in the constructor of proto.Message
30+
{"mapping", "ignore_unknown_fields"},
2831
)
2932
)

tests/unit/samplegen/test_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from gapic.samplegen_utils import (types, utils as gapic_utils)
2424
from gapic.schema import (naming, wrappers)
2525

26-
from tests.unit.samplegen.common_types import (DummyField, DummyMessage,
26+
from common_types import (DummyField, DummyMessage,
2727

2828
DummyMessageTypePB, DummyMethod, DummyService, DummyIdent,
2929
DummyApiSchema, DummyNaming, enum_factory, message_factory)

tests/unit/samplegen/test_template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
from gapic.samplegen_utils.types import CallingForm
2323
from textwrap import dedent
24-
from tests.unit.samplegen import common_types
24+
import common_types
2525

2626

2727
def check_template(template_fragment, expected_output, **kwargs):

tests/unit/schema/wrappers/test_field.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,12 @@ def test_field_name_kword_disambiguation():
357357
)
358358
assert frum_field.name == "frum"
359359

360+
mapping_field = make_field(name="mapping")
361+
assert mapping_field.name == "mapping_"
362+
363+
ignore_field = make_field(name="ignore_unknown_fields")
364+
assert ignore_field.name == "ignore_unknown_fields_"
365+
360366

361367
def test_field_resource_reference():
362368
field = make_field(name='parent', type='TYPE_STRING')

0 commit comments

Comments
 (0)