Fix compilation of fields with name identical to their type (#294)

* Revert "Fix compilation of fields named 'bytes' or 'str' (#226)"

This reverts commit deb623ed14.

* Fix compilation of fileds with name identical to their type

* Added test for field-name identical to python type

Co-authored-by: Guy Szweigman <guysz@nvidia.com>
This commit is contained in:
guysz
2021-12-01 18:31:02 +02:00
committed by GitHub
parent a4d2d39546
commit b0a36d12e4
4 changed files with 38 additions and 13 deletions

View File

@@ -133,16 +133,6 @@ 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 is_reserved_name(value) else value
return f"{value}_" if keyword.iskeyword(value) else value