Skip to content

Commit e81165d

Browse files
authored
Merge branch 'main' into benchling-allof-support
2 parents 8bbbf23 + dc05117 commit e81165d

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

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

openapi_python_client/parser/properties/enum_property.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def values_from_list(values: List[ValueType]) -> Dict[str, ValueType]:
5252
else:
5353
output[f"VALUE_{value}"] = value
5454
continue
55-
if value[0].isalpha():
55+
if value and value[0].isalpha():
5656
key = value.upper()
5757
else:
5858
key = f"VALUE_{i}"

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:

tests/test_parser/test_properties/test_init.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ def test_get_imports(self, mocker):
508508
def test_values_from_list(self):
509509
from openapi_python_client.parser.properties import EnumProperty
510510

511-
data = ["abc", "123", "a23", "1bc", 4, -3, "a Thing WIth spaces"]
511+
data = ["abc", "123", "a23", "1bc", 4, -3, "a Thing WIth spaces", ""]
512512

513513
result = EnumProperty.values_from_list(data)
514514

@@ -520,6 +520,7 @@ def test_values_from_list(self):
520520
"VALUE_4": 4,
521521
"VALUE_NEGATIVE_3": -3,
522522
"A_THING_WITH_SPACES": "a Thing WIth spaces",
523+
"VALUE_7": "",
523524
}
524525

525526
def test_values_from_list_duplicate(self):

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)