Improve logic to avoid keyword collisions in generated code

Use the standard library keyword module instead of a hard coded list and applying it to enum keys as well.
This commit is contained in:
James
2020-08-09 11:41:41 +01:00
committed by GitHub
parent 804805f0f5
commit 80bef7c94f
2 changed files with 10 additions and 37 deletions

View File

@@ -54,6 +54,8 @@ from betterproto.compile.naming import (
pythonize_method_name,
)
from ..casing import sanitize_name
try:
# betterproto[compiler] specific dependencies
from google.protobuf.compiler import plugin_pb2 as plugin
@@ -542,7 +544,7 @@ class EnumDefinitionCompiler(MessageCompiler):
# Get entries/allowed values for this Enum
self.entries = [
self.EnumEntry(
name=entry_proto_value.name,
name=sanitize_name(entry_proto_value.name),
value=entry_proto_value.number,
comment=get_comment(
proto_file=self.proto_file, path=self.path + [2, entry_number]