Skip to content

Commit c0078e0

Browse files
committed
fix: Support attributes using builtin type names
Fixes #359
1 parent 17daa73 commit c0078e0

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

Diff for: end_to_end_tests/golden-record/my_test_api_client/models/validation_error.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ class ValidationError:
1111

1212
loc: List[str]
1313
msg: str
14-
type: str
14+
type_: str
1515

1616
def to_dict(self) -> Dict[str, Any]:
1717
loc = self.loc
1818

1919
msg = self.msg
20-
type = self.type
20+
type_ = self.type_
2121

2222
field_dict: Dict[str, Any] = {}
2323
field_dict.update(
2424
{
2525
"loc": loc,
2626
"msg": msg,
27-
"type": type,
27+
"type": type_,
2828
}
2929
)
3030

@@ -37,12 +37,12 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
3737

3838
msg = d.pop("msg")
3939

40-
type = d.pop("type")
40+
type_ = d.pop("type")
4141

4242
validation_error = cls(
4343
loc=loc,
4444
msg=msg,
45-
type=type,
45+
type_=type_,
4646
)
4747

4848
return validation_error

Diff for: openapi_python_client/utils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import builtins
12
import re
23
from keyword import iskeyword
34

@@ -15,7 +16,7 @@ def fix_keywords(value: str) -> str:
1516
return value
1617

1718

18-
RESERVED_WORDS = ("self",)
19+
RESERVED_WORDS = set(dir(builtins)).union({"self"})
1920

2021

2122
def fix_reserved_words(value: str) -> str:

Diff for: tests/test_utils.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ def test__fix_keywords():
3838
assert utils.fix_keywords("None") == "None_"
3939

4040

41-
def test__fix_reserved_words():
42-
assert utils.fix_reserved_words("self") == "self_"
41+
@pytest.mark.parametrize(
42+
"reserved_word, expected", [("self", "self_"), ("int", "int_"), ("dict", "dict_"), ("not_reserved", "not_reserved")]
43+
)
44+
def test__fix_reserved_words(reserved_word: str, expected: str):
45+
assert utils.fix_reserved_words(reserved_word) == expected
4346

4447

4548
def test_to_valid_python_identifier():

0 commit comments

Comments
 (0)