From 8aad2eea7aef99af216e57354a95dd30ca530963 Mon Sep 17 00:00:00 2001 From: Dov Shlachter Date: Wed, 15 Dec 2021 11:53:14 -0800 Subject: [PATCH 1/3] fix: add additional reserved names for disambiguation 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. --- gapic/utils/reserved_names.py | 3 +++ tests/unit/schema/wrappers/test_field.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/gapic/utils/reserved_names.py b/gapic/utils/reserved_names.py index cf87e83992..40d9301fa9 100644 --- a/gapic/utils/reserved_names.py +++ b/gapic/utils/reserved_names.py @@ -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"}, ) ) diff --git a/tests/unit/schema/wrappers/test_field.py b/tests/unit/schema/wrappers/test_field.py index 7c9bfacbd1..6aa207cb1c 100644 --- a/tests/unit/schema/wrappers/test_field.py +++ b/tests/unit/schema/wrappers/test_field.py @@ -357,6 +357,9 @@ def test_field_name_kword_disambiguation(): ) assert frum_field.name == "frum" + mapping_field = make_field(name="mapping") + assert mapping_field.name == "mapping_" + def test_field_resource_reference(): field = make_field(name='parent', type='TYPE_STRING') From 49b5425308b62cb9b49406c441377527aeba1e44 Mon Sep 17 00:00:00 2001 From: Dov Shlachter Date: Thu, 16 Dec 2021 10:51:14 -0800 Subject: [PATCH 2/3] Don't be so lazy with the test for the new reserved name --- tests/unit/schema/wrappers/test_field.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/unit/schema/wrappers/test_field.py b/tests/unit/schema/wrappers/test_field.py index 6aa207cb1c..f823104e77 100644 --- a/tests/unit/schema/wrappers/test_field.py +++ b/tests/unit/schema/wrappers/test_field.py @@ -360,6 +360,9 @@ def test_field_name_kword_disambiguation(): 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') From 27acba20bc90b3c4dd4d811e5857e39ea3f89fec Mon Sep 17 00:00:00 2001 From: Dov Shlachter Date: Thu, 16 Dec 2021 10:54:29 -0800 Subject: [PATCH 3/3] Fix an import --- tests/unit/samplegen/test_integration.py | 2 +- tests/unit/samplegen/test_template.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/samplegen/test_integration.py b/tests/unit/samplegen/test_integration.py index 75ae35ec5a..aefde2f1dc 100644 --- a/tests/unit/samplegen/test_integration.py +++ b/tests/unit/samplegen/test_integration.py @@ -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) diff --git a/tests/unit/samplegen/test_template.py b/tests/unit/samplegen/test_template.py index 5a4086868d..42b8bb2aad 100644 --- a/tests/unit/samplegen/test_template.py +++ b/tests/unit/samplegen/test_template.py @@ -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):