Skip to content

Commit c9964ee

Browse files
feat: Handle Any return type annotation better
1 parent 749baaf commit c9964ee

12 files changed

+122
-120
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from http import HTTPStatus
2-
from typing import Any, Dict, Union
2+
from typing import Any, Dict
33

44
import httpx
55

@@ -33,7 +33,7 @@ def _get_kwargs(
3333
}
3434

3535

36-
def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, HTTPValidationError, None]:
36+
def _parse_response(*, client: Client, response: httpx.Response) -> Any:
3737
if response.status_code == HTTPStatus.OK:
3838
return response.json()
3939
if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY:
@@ -46,7 +46,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, H
4646
return None
4747

4848

49-
def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError, None]]:
49+
def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]:
5050
return Response(
5151
status_code=HTTPStatus(response.status_code),
5252
content=response.content,
@@ -59,7 +59,7 @@ def sync_detailed(
5959
*,
6060
client: Client,
6161
json_body: AModel,
62-
) -> Response[Union[Any, HTTPValidationError, None]]:
62+
) -> Response[Any]:
6363
"""Path with callback
6464
6565
Try sending a request related to a callback
@@ -72,7 +72,7 @@ def sync_detailed(
7272
httpx.TimeoutException: If the request takes longer than Client.timeout.
7373
7474
Returns:
75-
Response[Union[Any, HTTPValidationError, None]]
75+
Response[Any]
7676
"""
7777

7878
kwargs = _get_kwargs(
@@ -92,7 +92,7 @@ def sync(
9292
*,
9393
client: Client,
9494
json_body: AModel,
95-
) -> Union[Any, HTTPValidationError, None]:
95+
) -> Any:
9696
"""Path with callback
9797
9898
Try sending a request related to a callback
@@ -105,7 +105,7 @@ def sync(
105105
httpx.TimeoutException: If the request takes longer than Client.timeout.
106106
107107
Returns:
108-
Response[Union[Any, HTTPValidationError, None]]
108+
Response[Any]
109109
"""
110110

111111
return sync_detailed(
@@ -118,7 +118,7 @@ async def asyncio_detailed(
118118
*,
119119
client: Client,
120120
json_body: AModel,
121-
) -> Response[Union[Any, HTTPValidationError, None]]:
121+
) -> Response[Any]:
122122
"""Path with callback
123123
124124
Try sending a request related to a callback
@@ -131,7 +131,7 @@ async def asyncio_detailed(
131131
httpx.TimeoutException: If the request takes longer than Client.timeout.
132132
133133
Returns:
134-
Response[Union[Any, HTTPValidationError, None]]
134+
Response[Any]
135135
"""
136136

137137
kwargs = _get_kwargs(
@@ -149,7 +149,7 @@ async def asyncio(
149149
*,
150150
client: Client,
151151
json_body: AModel,
152-
) -> Union[Any, HTTPValidationError, None]:
152+
) -> Any:
153153
"""Path with callback
154154
155155
Try sending a request related to a callback
@@ -162,7 +162,7 @@ async def asyncio(
162162
httpx.TimeoutException: If the request takes longer than Client.timeout.
163163
164164
Returns:
165-
Response[Union[Any, HTTPValidationError, None]]
165+
Response[Any]
166166
"""
167167

168168
return (

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def _get_kwargs(
100100
}
101101

102102

103-
def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, HTTPValidationError, None]:
103+
def _parse_response(*, client: Client, response: httpx.Response) -> Any:
104104
if response.status_code == HTTPStatus.OK:
105105
return response.json()
106106
if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY:
@@ -113,7 +113,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, H
113113
return None
114114

115115

116-
def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError, None]]:
116+
def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]:
117117
return Response(
118118
status_code=HTTPStatus(response.status_code),
119119
content=response.content,
@@ -136,7 +136,7 @@ def sync_detailed(
136136
enum_prop: AnEnum,
137137
model_prop: "ModelWithUnionProperty",
138138
required_model_prop: "ModelWithUnionProperty",
139-
) -> Response[Union[Any, HTTPValidationError, None]]:
139+
) -> Response[Any]:
140140
"""Defaults
141141
142142
Args:
@@ -157,7 +157,7 @@ def sync_detailed(
157157
httpx.TimeoutException: If the request takes longer than Client.timeout.
158158
159159
Returns:
160-
Response[Union[Any, HTTPValidationError, None]]
160+
Response[Any]
161161
"""
162162

163163
kwargs = _get_kwargs(
@@ -197,7 +197,7 @@ def sync(
197197
enum_prop: AnEnum,
198198
model_prop: "ModelWithUnionProperty",
199199
required_model_prop: "ModelWithUnionProperty",
200-
) -> Union[Any, HTTPValidationError, None]:
200+
) -> Any:
201201
"""Defaults
202202
203203
Args:
@@ -218,7 +218,7 @@ def sync(
218218
httpx.TimeoutException: If the request takes longer than Client.timeout.
219219
220220
Returns:
221-
Response[Union[Any, HTTPValidationError, None]]
221+
Response[Any]
222222
"""
223223

224224
return sync_detailed(
@@ -251,7 +251,7 @@ async def asyncio_detailed(
251251
enum_prop: AnEnum,
252252
model_prop: "ModelWithUnionProperty",
253253
required_model_prop: "ModelWithUnionProperty",
254-
) -> Response[Union[Any, HTTPValidationError, None]]:
254+
) -> Response[Any]:
255255
"""Defaults
256256
257257
Args:
@@ -272,7 +272,7 @@ async def asyncio_detailed(
272272
httpx.TimeoutException: If the request takes longer than Client.timeout.
273273
274274
Returns:
275-
Response[Union[Any, HTTPValidationError, None]]
275+
Response[Any]
276276
"""
277277

278278
kwargs = _get_kwargs(
@@ -310,7 +310,7 @@ async def asyncio(
310310
enum_prop: AnEnum,
311311
model_prop: "ModelWithUnionProperty",
312312
required_model_prop: "ModelWithUnionProperty",
313-
) -> Union[Any, HTTPValidationError, None]:
313+
) -> Any:
314314
"""Defaults
315315
316316
Args:
@@ -331,7 +331,7 @@ async def asyncio(
331331
httpx.TimeoutException: If the request takes longer than Client.timeout.
332332
333333
Returns:
334-
Response[Union[Any, HTTPValidationError, None]]
334+
Response[Any]
335335
"""
336336

337337
return (

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from http import HTTPStatus
2-
from typing import Any, Dict, Union
2+
from typing import Any, Dict
33

44
import httpx
55

@@ -38,7 +38,7 @@ def _get_kwargs(
3838
}
3939

4040

41-
def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, HTTPValidationError, None]:
41+
def _parse_response(*, client: Client, response: httpx.Response) -> Any:
4242
if response.status_code == HTTPStatus.OK:
4343
return response.json()
4444
if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY:
@@ -51,7 +51,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, H
5151
return None
5252

5353

54-
def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError, None]]:
54+
def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]:
5555
return Response(
5656
status_code=HTTPStatus(response.status_code),
5757
content=response.content,
@@ -64,7 +64,7 @@ def sync_detailed(
6464
*,
6565
client: Client,
6666
int_enum: AnIntEnum,
67-
) -> Response[Union[Any, HTTPValidationError, None]]:
67+
) -> Response[Any]:
6868
"""Int Enum
6969
7070
Args:
@@ -75,7 +75,7 @@ def sync_detailed(
7575
httpx.TimeoutException: If the request takes longer than Client.timeout.
7676
7777
Returns:
78-
Response[Union[Any, HTTPValidationError, None]]
78+
Response[Any]
7979
"""
8080

8181
kwargs = _get_kwargs(
@@ -95,7 +95,7 @@ def sync(
9595
*,
9696
client: Client,
9797
int_enum: AnIntEnum,
98-
) -> Union[Any, HTTPValidationError, None]:
98+
) -> Any:
9999
"""Int Enum
100100
101101
Args:
@@ -106,7 +106,7 @@ def sync(
106106
httpx.TimeoutException: If the request takes longer than Client.timeout.
107107
108108
Returns:
109-
Response[Union[Any, HTTPValidationError, None]]
109+
Response[Any]
110110
"""
111111

112112
return sync_detailed(
@@ -119,7 +119,7 @@ async def asyncio_detailed(
119119
*,
120120
client: Client,
121121
int_enum: AnIntEnum,
122-
) -> Response[Union[Any, HTTPValidationError, None]]:
122+
) -> Response[Any]:
123123
"""Int Enum
124124
125125
Args:
@@ -130,7 +130,7 @@ async def asyncio_detailed(
130130
httpx.TimeoutException: If the request takes longer than Client.timeout.
131131
132132
Returns:
133-
Response[Union[Any, HTTPValidationError, None]]
133+
Response[Any]
134134
"""
135135

136136
kwargs = _get_kwargs(
@@ -148,7 +148,7 @@ async def asyncio(
148148
*,
149149
client: Client,
150150
int_enum: AnIntEnum,
151-
) -> Union[Any, HTTPValidationError, None]:
151+
) -> Any:
152152
"""Int Enum
153153
154154
Args:
@@ -159,7 +159,7 @@ async def asyncio(
159159
httpx.TimeoutException: If the request takes longer than Client.timeout.
160160
161161
Returns:
162-
Response[Union[Any, HTTPValidationError, None]]
162+
Response[Any]
163163
"""
164164

165165
return (

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from http import HTTPStatus
2-
from typing import Any, Dict, Union
2+
from typing import Any, Dict
33

44
import httpx
55

@@ -33,7 +33,7 @@ def _get_kwargs(
3333
}
3434

3535

36-
def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, HTTPValidationError, None]:
36+
def _parse_response(*, client: Client, response: httpx.Response) -> Any:
3737
if response.status_code == HTTPStatus.OK:
3838
return response.json()
3939
if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY:
@@ -46,7 +46,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, H
4646
return None
4747

4848

49-
def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError, None]]:
49+
def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]:
5050
return Response(
5151
status_code=HTTPStatus(response.status_code),
5252
content=response.content,
@@ -59,7 +59,7 @@ def sync_detailed(
5959
*,
6060
client: Client,
6161
json_body: AModel,
62-
) -> Response[Union[Any, HTTPValidationError, None]]:
62+
) -> Response[Any]:
6363
"""Json Body
6464
6565
Try sending a JSON body
@@ -72,7 +72,7 @@ def sync_detailed(
7272
httpx.TimeoutException: If the request takes longer than Client.timeout.
7373
7474
Returns:
75-
Response[Union[Any, HTTPValidationError, None]]
75+
Response[Any]
7676
"""
7777

7878
kwargs = _get_kwargs(
@@ -92,7 +92,7 @@ def sync(
9292
*,
9393
client: Client,
9494
json_body: AModel,
95-
) -> Union[Any, HTTPValidationError, None]:
95+
) -> Any:
9696
"""Json Body
9797
9898
Try sending a JSON body
@@ -105,7 +105,7 @@ def sync(
105105
httpx.TimeoutException: If the request takes longer than Client.timeout.
106106
107107
Returns:
108-
Response[Union[Any, HTTPValidationError, None]]
108+
Response[Any]
109109
"""
110110

111111
return sync_detailed(
@@ -118,7 +118,7 @@ async def asyncio_detailed(
118118
*,
119119
client: Client,
120120
json_body: AModel,
121-
) -> Response[Union[Any, HTTPValidationError, None]]:
121+
) -> Response[Any]:
122122
"""Json Body
123123
124124
Try sending a JSON body
@@ -131,7 +131,7 @@ async def asyncio_detailed(
131131
httpx.TimeoutException: If the request takes longer than Client.timeout.
132132
133133
Returns:
134-
Response[Union[Any, HTTPValidationError, None]]
134+
Response[Any]
135135
"""
136136

137137
kwargs = _get_kwargs(
@@ -149,7 +149,7 @@ async def asyncio(
149149
*,
150150
client: Client,
151151
json_body: AModel,
152-
) -> Union[Any, HTTPValidationError, None]:
152+
) -> Any:
153153
"""Json Body
154154
155155
Try sending a JSON body
@@ -162,7 +162,7 @@ async def asyncio(
162162
httpx.TimeoutException: If the request takes longer than Client.timeout.
163163
164164
Returns:
165-
Response[Union[Any, HTTPValidationError, None]]
165+
Response[Any]
166166
"""
167167

168168
return (

0 commit comments

Comments
 (0)