Skip to content

Commit

Permalink
Remove logic that collides with module name/keyword collision fixing
Browse files Browse the repository at this point in the history
This previous logic was a workaroudn to a similar problem.
  • Loading branch information
software-dov committed Sep 15, 2020
1 parent 7f1515c commit d9174bb
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 51 deletions.
14 changes: 0 additions & 14 deletions gapic/schema/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,19 +224,6 @@ def build(
file_descriptors,
), opts=opts)

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 RESERVED_NAMES or full_path in visited_names:
name += "_"
full_path = os.path.join(path, name + ext)
if full_path in visited_names:
return disambiguate_keyword_fname(full_path, visited_names)

return full_path

# Iterate over each FileDescriptorProto and fill out a Proto
# object describing it, and save these to the instance.
#
Expand All @@ -252,7 +239,6 @@ def disambiguate_keyword_fname(
# load the services and methods with the full scope of types.
pre_protos: Dict[str, Proto] = dict(prior_protos or {})
for fd in file_descriptors:
fd.name = disambiguate_keyword_fname(fd.name, pre_protos)
pre_protos[fd.name] = Proto.build(
file_descriptor=fd,
file_to_generate=fd.package.startswith(package),
Expand Down
37 changes: 0 additions & 37 deletions tests/unit/schema/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,43 +203,6 @@ def test_proto_names():
assert proto.disambiguate('foo') == '_foo'


def test_proto_keyword_fname():
# Protos with filenames that happen to be python keywords
# cannot be directly imported.
# Check that the file names are unspecialized when building the API object.
fd = (
make_file_pb2(
name='import.proto',
package='google.keywords.v1',
messages=(make_message_pb2(name='ImportRequest', fields=()),),
),
make_file_pb2(
name='import_.proto',
package='google.keywords.v1',
messages=(make_message_pb2(name='ImportUnderRequest', fields=()),),
),
make_file_pb2(
name='class_.proto',
package='google.keywords.v1',
messages=(make_message_pb2(name='ClassUnderRequest', fields=()),),
),
make_file_pb2(
name='class.proto',
package='google.keywords.v1',
messages=(make_message_pb2(name='ClassRequest', fields=()),),
)
)

# We can't create new collisions, so check that renames cascade.
api_schema = api.API.build(fd, package='google.keywords.v1')
assert set(api_schema.protos.keys()) == {
'import_.proto',
'import__.proto',
'class_.proto',
'class__.proto',
}


def test_proto_oneof():
# Put together a couple of minimal protos.
fd = (
Expand Down

0 comments on commit d9174bb

Please sign in to comment.