diff --git a/CHANGELOG.md b/CHANGELOG.md index ea06972a00..5f4b3c3fae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +### [0.43.2](https://www.github.com/googleapis/gapic-generator-python/compare/v0.43.1...v0.43.2) (2021-03-24) + + +### Bug Fixes + +* add certain raw imports to RESERVED_NAMES ([#824](https://www.github.com/googleapis/gapic-generator-python/issues/824)) ([04bd8aa](https://www.github.com/googleapis/gapic-generator-python/commit/04bd8aaf0fc2c2c0615105cab39dc33266b66775)) +* Update module alias to resolve naming conflict ([#820](https://www.github.com/googleapis/gapic-generator-python/issues/820)) ([f5e9f36](https://www.github.com/googleapis/gapic-generator-python/commit/f5e9f367ec6a72b4272f559a93f6fbb3d7e54b8b)), closes [#819](https://www.github.com/googleapis/gapic-generator-python/issues/819) + ### [0.43.1](https://www.github.com/googleapis/gapic-generator-python/compare/v0.43.0...v0.43.1) (2021-03-19) diff --git a/gapic/schema/metadata.py b/gapic/schema/metadata.py index 0276fe0989..0b1f6df2d5 100644 --- a/gapic/schema/metadata.py +++ b/gapic/schema/metadata.py @@ -115,9 +115,12 @@ def module_alias(self) -> str: return '_'.join( ( ''.join( - i[0] - for i in self.package - if i != self.api_naming.version + [ + partial_name[0] + for i in self.package + for partial_name in i.split("_") + if i != self.api_naming.version + ] ), self.module, ) diff --git a/gapic/utils/reserved_names.py b/gapic/utils/reserved_names.py index 9bf1c9a914..9104015d5c 100644 --- a/gapic/utils/reserved_names.py +++ b/gapic/utils/reserved_names.py @@ -21,7 +21,15 @@ # They are explicitly allowed message, module, and field names. RESERVED_NAMES = frozenset( itertools.chain( + # We CANNOT make exceptions for keywords. keyword.kwlist, + # We make SOME exceptions for certain names that collide with builtins. set(dir(builtins)) - {"filter", "map", "id", "input", "property"}, + # This is a hand-maintained list of modules that are directly imported + # in templates, i.e. they are not added as dependencies to any type, + # the raw text is just there in the template. + # More can be added as collisions are discovered. + # See issue #819 for additional info. + {"auth", "credentials", "exceptions", "future", "options", "policy", "math"} ) ) diff --git a/requirements.txt b/requirements.txt index 2770b54084..4c5eb59b97 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ click==7.1.2 -google-api-core==1.26.1 +google-api-core==1.26.2 googleapis-common-protos==1.53.0 jinja2==2.11.3 MarkupSafe==1.1.1 diff --git a/tests/unit/schema/test_metadata.py b/tests/unit/schema/test_metadata.py index 4be166bc1b..693beffa9b 100644 --- a/tests/unit/schema/test_metadata.py +++ b/tests/unit/schema/test_metadata.py @@ -184,6 +184,14 @@ def test_address_name_builtin_keyword(): ) assert addr_kword.module_alias == "gp_class" + addr_kword = metadata.Address( + name="Class", + module="class", + package=("google", "appengine_admin"), + api_naming=naming.NewNaming(proto_package="foo.bar.baz.v1"), + ) + assert addr_kword.module_alias == "gaa_class" + def test_doc_nothing(): meta = metadata.Metadata()