fix: module names can no longer collide with keywords or builtins by software-dov · Pull Request #595 · googleapis/gapic-generator-python · GitHub
Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion gapic/schema/api.py
4 changes: 4 additions & 0 deletions gapic/schema/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from gapic.schema import imp
from gapic.schema import naming
from gapic.utils import cached_property
from gapic.utils import RESERVED_NAMES


@dataclasses.dataclass(frozen=True)
Expand All @@ -48,6 +49,9 @@ 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')])
Expand Down
13 changes: 12 additions & 1 deletion gapic/utils/reserved_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import builtins
import itertools
import keyword


RESERVED_NAMES = frozenset(keyword.kwlist)
# The filter and map builtins are a historical artifact;
# they are not used in modern, idiomatic python,
# nor are they used in the gapic surface.
# They are too useful to reserve.
RESERVED_NAMES = frozenset(
itertools.chain(
keyword.kwlist,
set(dir(builtins)) - {"filter", "map"},
)
)
24 changes: 22 additions & 2 deletions tests/unit/schema/test_metadata.py