diff --git a/gapic/schema/metadata.py b/gapic/schema/metadata.py index 4e78119f91..cd96ab86c3 100644 --- a/gapic/schema/metadata.py +++ b/gapic/schema/metadata.py @@ -49,9 +49,6 @@ class Address: ) collisions: FrozenSet[str] = dataclasses.field(default_factory=frozenset) - def __post_init__(self): - super().__setattr__("collisions", self.collisions | RESERVED_NAMES) - def __eq__(self, other) -> bool: return all([getattr(self, i) == getattr(other, i) for i in ('name', 'module', 'module_path', 'package', 'parent')]) @@ -114,7 +111,7 @@ def module_alias(self) -> str: while still providing names that are fundamentally readable to users (albeit looking auto-generated). """ - if self.module in self.collisions: + if self.module in self.collisions | RESERVED_NAMES: return '_'.join( ( ''.join( @@ -283,7 +280,7 @@ def with_context(self, *, collisions: FrozenSet[str]) -> 'Address': ``Address`` object aliases module names to avoid naming collisions in the file being written. """ - return dataclasses.replace(self, collisions=frozenset(collisions)) + return dataclasses.replace(self, collisions=collisions) @dataclasses.dataclass(frozen=True) diff --git a/gapic/schema/wrappers.py b/gapic/schema/wrappers.py index 7bad6adb3b..b5ae6fd0e9 100644 --- a/gapic/schema/wrappers.py +++ b/gapic/schema/wrappers.py @@ -314,13 +314,19 @@ def recursive_field_types(self) -> Sequence[ return tuple(types) @utils.cached_property - def recursive_fields(self) -> FrozenSet[Field]: - return frozenset(chain( + def recursive_resource_fields(self) -> FrozenSet[Field]: + all_fields = chain( self.fields.values(), (field for t in self.recursive_field_types if isinstance(t, MessageType) for field in t.fields.values()), - )) + ) + return frozenset( + f + for f in all_fields + if (f.options.Extensions[resource_pb2.resource_reference].type or + f.options.Extensions[resource_pb2.resource_reference].child_type) + ) @property def map(self) -> bool: @@ -1060,7 +1066,7 @@ def gen_resources(message): yield type_ def gen_indirect_resources_used(message): - for field in message.recursive_fields: + for field in message.recursive_resource_fields: resource = field.options.Extensions[ resource_pb2.resource_reference] resource_type = resource.type or resource.child_type