Fix compilation of fields named 'bytes' or 'str' (#226)
* if you have a field named "bytes" using the bytes type, it doesn't work. * Enable existing use-case & generalize solution to cover it Co-authored-by: Spencer <spencer@sf-n.com>
This commit is contained in:
parent
95339bf74d
commit
deb623ed14
@ -133,6 +133,16 @@ def lowercase_first(value: str) -> str:
|
||||
return value[0:1].lower() + value[1:]
|
||||
|
||||
|
||||
def is_reserved_name(value: str) -> bool:
|
||||
if keyword.iskeyword(value):
|
||||
return True
|
||||
|
||||
if value in ("bytes", "str"):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def sanitize_name(value: str) -> str:
|
||||
# https://www.python.org/dev/peps/pep-0008/#descriptive-naming-styles
|
||||
return f"{value}_" if keyword.iskeyword(value) else value
|
||||
return f"{value}_" if is_reserved_name(value) else value
|
||||
|
@ -2,7 +2,6 @@
|
||||
# Remove from list when fixed.
|
||||
xfail = {
|
||||
"namespace_keywords", # 70
|
||||
"namespace_builtin_types", # 53
|
||||
"googletypes_struct", # 9
|
||||
"googletypes_value", # 9
|
||||
"import_capitalized_package",
|
||||
|
Loading…
x
Reference in New Issue
Block a user