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:
nat 2021-04-06 02:45:57 +02:00 committed by GitHub
parent 95339bf74d
commit deb623ed14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -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

View File

@ -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",