Skip to content

fix: Support attributes using builtin type names #360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ class ValidationError:

loc: List[str]
msg: str
type: str
type_: str

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

msg = self.msg
type = self.type
type_ = self.type_

field_dict: Dict[str, Any] = {}
field_dict.update(
{
"loc": loc,
"msg": msg,
"type": type,
"type": type_,
}
)

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

msg = d.pop("msg")

type = d.pop("type")
type_ = d.pop("type")

validation_error = cls(
loc=loc,
msg=msg,
type=type,
type_=type_,
)

return validation_error
3 changes: 2 additions & 1 deletion openapi_python_client/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import builtins
import re
from keyword import iskeyword

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


RESERVED_WORDS = ("self",)
RESERVED_WORDS = set(dir(builtins)).union({"self"})


def fix_reserved_words(value: str) -> str:
Expand Down
7 changes: 5 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ def test__fix_keywords():
assert utils.fix_keywords("None") == "None_"


def test__fix_reserved_words():
assert utils.fix_reserved_words("self") == "self_"
@pytest.mark.parametrize(
"reserved_word, expected", [("self", "self_"), ("int", "int_"), ("dict", "dict_"), ("not_reserved", "not_reserved")]
)
def test__fix_reserved_words(reserved_word: str, expected: str):
assert utils.fix_reserved_words(reserved_word) == expected


def test_to_valid_python_identifier():
Expand Down