From 2c137f1f621a2a588f9de2a2698d13ba7fbc2b26 Mon Sep 17 00:00:00 2001 From: Bu Sun Kim Date: Wed, 12 May 2021 21:19:12 +0000 Subject: [PATCH 1/3] fix: consistently use _pb2 identifier --- gapic/schema/metadata.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gapic/schema/metadata.py b/gapic/schema/metadata.py index e14190d007..91e6905777 100644 --- a/gapic/schema/metadata.py +++ b/gapic/schema/metadata.py @@ -84,17 +84,17 @@ def __str__(self) -> str: if self.module: module_name = self.module + # If collisions are registered and conflict with our module, + # use the module alias instead. + if self.module_alias: + module_name = self.module_alias + # This module is from a different proto package # Most commonly happens for a common proto # https://pypi.org/project/googleapis-common-protos/ if not self.proto_package.startswith(self.api_naming.proto_package): module_name = f'{self.module}_pb2' - # If collisions are registered and conflict with our module, - # use the module alias instead. - if self.module_alias: - module_name = self.module_alias - # Return the dot-separated Python identifier. return '.'.join((module_name,) + self.parent + (self.name,)) From 77086dd59c04c3231ad75055484dfc9c82dab5fd Mon Sep 17 00:00:00 2001 From: Bu Sun Kim Date: Wed, 12 May 2021 23:23:43 +0000 Subject: [PATCH 2/3] test: add unit test --- tests/unit/schema/test_metadata.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/unit/schema/test_metadata.py b/tests/unit/schema/test_metadata.py index c778000c7c..c11dfc7313 100644 --- a/tests/unit/schema/test_metadata.py +++ b/tests/unit/schema/test_metadata.py @@ -49,6 +49,17 @@ def test_address_str_different_proto_package(): assert str(addr) == 'options_pb2.GetPolicyOptions' +def test_address_str_different_proto_package_with_collision(): + addr = metadata.Address( + package=('google', 'rpc'), + module='status', + name='Status', + api_naming=naming.NewNaming(proto_package='foo.bar.baz.v1') + ).with_context(collisions=frozenset({'status'})) + # the module alias should be ignored for _pb2 types + assert str(addr) == 'status_pb2.Status' + + def test_address_proto(): addr = metadata.Address(package=('foo', 'bar'), module='baz', name='Bacon') assert addr.proto == 'foo.bar.Bacon' From 1db98204d04f940093d5e0068e659659b86a8aab Mon Sep 17 00:00:00 2001 From: Bu Sun Kim Date: Wed, 12 May 2021 23:38:41 +0000 Subject: [PATCH 3/3] chore: fix formatting --- tests/unit/schema/test_metadata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/schema/test_metadata.py b/tests/unit/schema/test_metadata.py index c11dfc7313..179361e039 100644 --- a/tests/unit/schema/test_metadata.py +++ b/tests/unit/schema/test_metadata.py @@ -56,7 +56,7 @@ def test_address_str_different_proto_package_with_collision(): name='Status', api_naming=naming.NewNaming(proto_package='foo.bar.baz.v1') ).with_context(collisions=frozenset({'status'})) - # the module alias should be ignored for _pb2 types + # the module alias should be ignored for _pb2 types assert str(addr) == 'status_pb2.Status'