Skip to content

Commit deb623e

Browse files
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 <[email protected]>
1 parent 95339bf commit deb623e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/betterproto/casing.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ def lowercase_first(value: str) -> str:
133133
return value[0:1].lower() + value[1:]
134134

135135

136+
def is_reserved_name(value: str) -> bool:
137+
if keyword.iskeyword(value):
138+
return True
139+
140+
if value in ("bytes", "str"):
141+
return True
142+
143+
return False
144+
145+
136146
def sanitize_name(value: str) -> str:
137147
# https://www.python.org/dev/peps/pep-0008/#descriptive-naming-styles
138-
return f"{value}_" if keyword.iskeyword(value) else value
148+
return f"{value}_" if is_reserved_name(value) else value

tests/inputs/config.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Remove from list when fixed.
33
xfail = {
44
"namespace_keywords", # 70
5-
"namespace_builtin_types", # 53
65
"googletypes_struct", # 9
76
"googletypes_value", # 9
87
"import_capitalized_package",

0 commit comments

Comments
 (0)