Skip to content

Commit

Permalink
fix: add additional reserved names for disambiguation (#1114)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
software-dov authored Dec 28, 2021
1 parent cafcbfb commit 1cffd8d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions gapic/utils/reserved_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@
keyword.kwlist,
# We make SOME exceptions for certain names that collide with builtins.
set(dir(builtins)) - {"filter", "map", "id", "input", "property"},
# "mapping" and "ignore_unknown_fields" have special uses
# in the constructor of proto.Message
{"mapping", "ignore_unknown_fields"},
)
)
2 changes: 1 addition & 1 deletion tests/unit/samplegen/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from gapic.samplegen_utils import (types, utils as gapic_utils)
from gapic.schema import (naming, wrappers)

from tests.unit.samplegen.common_types import (DummyField, DummyMessage,
from common_types import (DummyField, DummyMessage,

DummyMessageTypePB, DummyMethod, DummyService, DummyIdent,
DummyApiSchema, DummyNaming, enum_factory, message_factory)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/samplegen/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from gapic.samplegen_utils.types import CallingForm
from textwrap import dedent
from tests.unit.samplegen import common_types
import common_types


def check_template(template_fragment, expected_output, **kwargs):
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/schema/wrappers/test_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,12 @@ def test_field_name_kword_disambiguation():
)
assert frum_field.name == "frum"

mapping_field = make_field(name="mapping")
assert mapping_field.name == "mapping_"

ignore_field = make_field(name="ignore_unknown_fields")
assert ignore_field.name == "ignore_unknown_fields_"


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

0 comments on commit 1cffd8d

Please sign in to comment.