Skip to content

Commit 961f6df

Browse files
committed
Fixed typing issues (again)
1 parent 8f7d51b commit 961f6df

File tree

15 files changed

+129
-114
lines changed

15 files changed

+129
-114
lines changed

end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,39 @@ def _get_kwargs(
2121
int_prop: Union[Unset, int] = 7,
2222
boolean_prop: Union[Unset, bool] = UNSET,
2323
list_prop: Union[Unset, List[AnEnum]] = UNSET,
24-
union_prop: Union[Unset, Union[Union[Unset, float], Union[Unset, str]]] = "not a float",
24+
union_prop: Union[Unset, Union[float, str]] = "not a float",
2525
enum_prop: Union[Unset, AnEnum] = UNSET,
2626
) -> Dict[str, Any]:
2727
url = "{}/tests/defaults".format(client.base_url)
2828

2929
headers: Dict[str, Any] = client.get_headers()
3030

31-
if datetime_prop is UNSET:
32-
json_datetime_prop = UNSET
33-
else:
31+
json_datetime_prop: Union[Unset, str] = UNSET
32+
if not isinstance(datetime_prop, Unset):
3433
json_datetime_prop = datetime_prop.isoformat()
3534

36-
if date_prop is UNSET:
37-
json_date_prop = UNSET
38-
else:
35+
json_date_prop: Union[Unset, str] = UNSET
36+
if not isinstance(date_prop, Unset):
3937
json_date_prop = date_prop.isoformat()
4038

41-
if list_prop is UNSET:
42-
json_list_prop = UNSET
43-
else:
39+
json_list_prop: Union[Unset, List[Any]] = UNSET
40+
if not isinstance(list_prop, Unset):
4441
json_list_prop = []
4542
for list_prop_item_data in list_prop:
4643
list_prop_item = list_prop_item_data.value
4744

4845
json_list_prop.append(list_prop_item)
4946

50-
if union_prop is UNSET:
51-
json_union_prop: Union[Unset, Union[Union[Unset, float], Union[Unset, str]]] = UNSET
47+
json_union_prop: Union[Unset, Union[float, str]]
48+
if isinstance(union_prop, Unset):
49+
json_union_prop = UNSET
5250
elif isinstance(union_prop, float):
5351
json_union_prop = union_prop
5452
else:
5553
json_union_prop = union_prop
5654

57-
if enum_prop is UNSET:
58-
json_enum_prop = UNSET
59-
else:
55+
json_enum_prop: Union[Unset, AnEnum] = UNSET
56+
if not isinstance(enum_prop, Unset):
6057
json_enum_prop = enum_prop.value
6158

6259
params: Dict[str, Any] = {}
@@ -119,7 +116,7 @@ def sync_detailed(
119116
int_prop: Union[Unset, int] = 7,
120117
boolean_prop: Union[Unset, bool] = UNSET,
121118
list_prop: Union[Unset, List[AnEnum]] = UNSET,
122-
union_prop: Union[Unset, Union[Union[Unset, float], Union[Unset, str]]] = "not a float",
119+
union_prop: Union[Unset, Union[float, str]] = "not a float",
123120
enum_prop: Union[Unset, AnEnum] = UNSET,
124121
) -> Response[Union[None, HTTPValidationError]]:
125122
kwargs = _get_kwargs(
@@ -154,7 +151,7 @@ def sync(
154151
int_prop: Union[Unset, int] = 7,
155152
boolean_prop: Union[Unset, bool] = UNSET,
156153
list_prop: Union[Unset, List[AnEnum]] = UNSET,
157-
union_prop: Union[Unset, Union[Union[Unset, float], Union[Unset, str]]] = "not a float",
154+
union_prop: Union[Unset, Union[float, str]] = "not a float",
158155
enum_prop: Union[Unset, AnEnum] = UNSET,
159156
) -> Optional[Union[None, HTTPValidationError]]:
160157
""" """
@@ -185,7 +182,7 @@ async def asyncio_detailed(
185182
int_prop: Union[Unset, int] = 7,
186183
boolean_prop: Union[Unset, bool] = UNSET,
187184
list_prop: Union[Unset, List[AnEnum]] = UNSET,
188-
union_prop: Union[Unset, Union[Union[Unset, float], Union[Unset, str]]] = "not a float",
185+
union_prop: Union[Unset, Union[float, str]] = "not a float",
189186
enum_prop: Union[Unset, AnEnum] = UNSET,
190187
) -> Response[Union[None, HTTPValidationError]]:
191188
kwargs = _get_kwargs(
@@ -219,7 +216,7 @@ async def asyncio(
219216
int_prop: Union[Unset, int] = 7,
220217
boolean_prop: Union[Unset, bool] = UNSET,
221218
list_prop: Union[Unset, List[AnEnum]] = UNSET,
222-
union_prop: Union[Unset, Union[Union[Unset, float], Union[Unset, str]]] = "not a float",
219+
union_prop: Union[Unset, Union[float, str]] = "not a float",
223220
enum_prop: Union[Unset, AnEnum] = UNSET,
224221
) -> Optional[Union[None, HTTPValidationError]]:
225222
""" """

end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ def _get_kwargs(
1616

1717
headers: Dict[str, Any] = client.get_headers()
1818

19-
if query_param is UNSET:
20-
json_query_param = UNSET
21-
else:
19+
json_query_param: Union[Unset, List[Any]] = UNSET
20+
if not isinstance(query_param, Unset):
2221
json_query_param = query_param
2322

2423
params: Dict[str, Any] = {}

end_to_end_tests/golden-record/my_test_api_client/models/a_model.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,10 @@ def to_dict(self) -> Dict[str, Any]:
3636
a_date = self.a_date.isoformat()
3737

3838
required_not_nullable = self.required_not_nullable
39-
40-
if self.nested_list_of_enums is UNSET:
41-
nested_list_of_enums = UNSET
42-
else:
39+
nested_list_of_enums: Union[Unset, List[Any]] = UNSET
40+
if not isinstance(self.nested_list_of_enums, Unset):
4341
nested_list_of_enums = []
4442
for nested_list_of_enums_item_data in self.nested_list_of_enums:
45-
4643
nested_list_of_enums_item = []
4744
for nested_list_of_enums_item_item_data in nested_list_of_enums_item_data:
4845
nested_list_of_enums_item_item = nested_list_of_enums_item_item_data.value

end_to_end_tests/golden-record/my_test_api_client/models/http_validation_error.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ class HTTPValidationError:
1313
detail: Union[Unset, List[ValidationError]] = UNSET
1414

1515
def to_dict(self) -> Dict[str, Any]:
16-
17-
if self.detail is UNSET:
18-
detail = UNSET
19-
else:
16+
detail: Union[Unset, List[Any]] = UNSET
17+
if not isinstance(self.detail, Unset):
2018
detail = []
2119
for detail_item_data in self.detail:
2220
detail_item = detail_item_data.to_dict()

end_to_end_tests/golden-record/my_test_api_client/models/validation_error.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ class ValidationError:
1212
type: str
1313

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

1817
msg = self.msg

openapi_python_client/parser/properties.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def get_type_string(self, no_optional: bool = False, no_unset: bool = False) ->
229229
""" Get a string representation of type that should be used when declaring this property """
230230
type_string = f"List[{self.inner_property.get_type_string()}]"
231231
if not no_optional and self.nullable:
232-
type_string = f"Optional[{type_string}]"
232+
type_string = f"Optional[{type_string}]"
233233
if not no_unset and not self.required:
234234
type_string = f"Union[Unset, {type_string}]"
235235
return type_string
@@ -260,7 +260,7 @@ class UnionProperty(Property):
260260

261261
def get_type_string(self, no_optional: bool = False, no_unset: bool = False) -> str:
262262
""" Get a string representation of type that should be used when declaring this property """
263-
inner_types = [p.get_type_string() for p in self.inner_properties]
263+
inner_types = [p.get_type_string(no_unset=True) for p in self.inner_properties]
264264
inner_prop_string = ", ".join(inner_types)
265265
type_string = f"Union[{inner_prop_string}]"
266266
if not no_optional and self.nullable:

openapi_python_client/templates/property_templates/date_property.pyi

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ if {{ source }} is not None:
1616
{{ destination }} = {{ source }}.isoformat()
1717
{% endif %}
1818
{% else %}
19-
if {{ source }} is UNSET:
20-
{{ destination }} = UNSET
19+
{{ destination }}: Union[Unset, str] = UNSET
20+
if not isinstance({{ source }}, Unset):
2121
{% if property.nullable %}
22-
else:
2322
{{ destination }} = {{ source }}.isoformat() if {{ source }} else None
2423
{% else %}
25-
else:
2624
{{ destination }} = {{ source }}.isoformat()
2725
{% endif %}
2826
{% endif %}

openapi_python_client/templates/property_templates/datetime_property.pyi

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ if {{ source }} is not None:
1616
{{ destination }} = {{ source }}.isoformat()
1717
{% endif %}
1818
{% else %}
19-
if {{ source }} is UNSET:
20-
{{ destination }} = UNSET
19+
{{ destination }}: Union[Unset, str] = UNSET
20+
if not isinstance({{ source }}, Unset):
2121
{% if property.nullable %}
22-
else:
2322
{{ destination }} = {{ source }}.isoformat() if {{ source }} else None
2423
{% else %}
25-
else:
2624
{{ destination }} = {{ source }}.isoformat()
2725
{% endif %}
2826
{% endif %}

openapi_python_client/templates/property_templates/enum_property.pyi

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ if {{ source }} is not None:
1616
{{ destination }} = {{ source }}.value
1717
{% endif %}
1818
{% else %}
19-
if {{ source }} is UNSET:
20-
{{ destination }} = UNSET
19+
{{ destination }}: {{ property.get_type_string() }} = UNSET
20+
if not isinstance({{ source }}, Unset):
2121
{% if property.nullable %}
22-
else:
2322
{{ destination }} = {{ source }}.value if {{ source }} else None
2423
{% else %}
25-
else:
2624
{{ destination }} = {{ source }}.value
2725
{% endif %}
2826
{% endif %}

openapi_python_client/templates/property_templates/file_property.pyi

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@
1111
{{ destination }} = {{ source }}.to_tuple()
1212
{% endif %}
1313
{% else %}
14-
if {{ source }} is UNSET:
15-
{{ destination }} = UNSET
14+
{{ destination }}: {{ property.get_type_string() }} = UNSET
15+
if not isinstance({{ source }}, Unset):
1616
{% if property.nullable %}
17-
else:
1817
{{ destination }} = {{ source }}.to_tuple() if {{ source }} else None
1918
{% else %}
20-
else:
2119
{{ destination }} = {{ source }}.to_tuple()
2220
{% endif %}
2321
{% endif %}

openapi_python_client/templates/property_templates/list_property.pyi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ for {{ inner_source }} in {{ source }}:
3333

3434
{% macro transform(property, source, destination) %}
3535
{% set inner_property = property.inner_property %}
36-
37-
3836
{% if property.required %}
3937
{% if property.nullable %}
4038
if {{ source }} is None:
@@ -45,15 +43,17 @@ else:
4543
{{ _transform(property, source, destination) }}
4644
{% endif %}
4745
{% else %}
48-
if {{ source }} is UNSET:
49-
{{ destination }} = UNSET
46+
{{ destination }}: Union[Unset, List[Any]] = UNSET
47+
if not isinstance({{ source }}, Unset):
5048
{% if property.nullable %}
51-
elif {{ source }} is None:
52-
{{ destination }} = None
53-
{% endif %}
54-
else:
49+
if {{ source }} is None:
50+
{{ destination }} = None
51+
else:
52+
{{ _transform(property, source, destination) | indent(4)}}
53+
{% else %}
5554
{{ _transform(property, source, destination) | indent(4)}}
5655
{% endif %}
56+
{% endif %}
5757

5858

5959
{% endmacro %}

openapi_python_client/templates/property_templates/ref_property.pyi

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ if {{ source }} is not None:
1616
{{ destination }} = {{ source }}.to_dict()
1717
{% endif %}
1818
{% else %}
19-
if {{ source }} is UNSET:
20-
{{ destination }} = UNSET
19+
{{ destination }}: {{ property.get_type_string() }} = UNSET
20+
if not isinstance({{ source }}, Unset):
2121
{% if property.nullable %}
22-
else:
2322
{{ destination }} = {{ source }}.to_dict() if {{ source }} else None
2423
{% else %}
25-
else:
2624
{{ destination }} = {{ source }}.to_dict()
2725
{% endif %}
2826
{% endif %}

openapi_python_client/templates/property_templates/union_property.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ def _parse_{{ property.python_name }}(data: Dict[str, Any]) -> {{ property.get_t
2323

2424
{% macro transform(property, source, destination) %}
2525
{% if not property.required %}
26-
if {{ source }} is UNSET:
27-
{{ destination }}: {{ property.get_type_string() }} = UNSET
26+
{{ destination }}: {{ property.get_type_string() }}
27+
if isinstance({{ source }}, Unset):
28+
{{ destination }} = UNSET
2829
{% endif %}
2930
{% if property.nullable %}
3031
{% if property.required %}

openapi_python_client/templates/types.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
""" Contains some shared types for properties """
2-
from typing import Any, BinaryIO, Generic, MutableMapping, NewType, Optional, TextIO, Tuple, TypeVar, Union
2+
from typing import BinaryIO, Generic, MutableMapping, Optional, TextIO, Tuple, TypeVar, Union
33

44
import attr
55

6+
67
class Unset:
78
pass
9+
10+
811
UNSET: Unset = Unset()
912

1013

0 commit comments

Comments
 (0)