Skip to content

Commit

Permalink
Merge branch 'main' into snippetgen-default
Browse files Browse the repository at this point in the history
  • Loading branch information
busunkim96 authored Jan 28, 2022
2 parents 02e5331 + 8078961 commit 0cc14b8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
6 changes: 5 additions & 1 deletion gapic/schema/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,16 @@ def build(
file_descriptors,
), opts=opts)

# "metadata", "retry", "timeout", and "request" are reserved words in client methods.
invalid_module_names = set(keyword.kwlist) | {
"metadata", "retry", "timeout", "request"}

def disambiguate_keyword_fname(
full_path: str,
visited_names: Container[str]) -> str:
path, fname = os.path.split(full_path)
name, ext = os.path.splitext(fname)
if name in keyword.kwlist or full_path in visited_names:
if name in invalid_module_names or full_path in visited_names:
name += "_"
full_path = os.path.join(path, name + ext)
if full_path in visited_names:
Expand Down
26 changes: 25 additions & 1 deletion tests/unit/schema/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,27 @@ def test_proto_keyword_fname():
name='class.proto',
package='google.keywords.v1',
messages=(make_message_pb2(name='ClassRequest', fields=()),),
)
),
make_file_pb2(
name='metadata.proto',
package='google.keywords.v1',
messages=(make_message_pb2(name='MetadataRequest', fields=()),),
),
make_file_pb2(
name='retry.proto',
package='google.keywords.v1',
messages=(make_message_pb2(name='RetryRequest', fields=()),),
),
make_file_pb2(
name='timeout.proto',
package='google.keywords.v1',
messages=(make_message_pb2(name='TimeoutRequest', fields=()),),
),
make_file_pb2(
name='request.proto',
package='google.keywords.v1',
messages=(make_message_pb2(name='RequestRequest', fields=()),),
),
)

# We can't create new collisions, so check that renames cascade.
Expand All @@ -243,6 +263,10 @@ def test_proto_keyword_fname():
'import__.proto',
'class_.proto',
'class__.proto',
'metadata_.proto',
'retry_.proto',
'timeout_.proto',
'request_.proto',
}


Expand Down

0 comments on commit 0cc14b8

Please sign in to comment.