Skip to content

Commit b666c4c

Browse files
fix: Ignore mypy error when returning None
This was introduced in "fix: Make empty response a `NoneProperty`", but is easier to fix now with the refactored endpoint_module.py.jinja.
1 parent 82a3c87 commit b666c4c

17 files changed

+25
-20
lines changed

end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Non
4848
status_code=HTTPStatus(response.status_code),
4949
content=response.content,
5050
headers=response.headers,
51-
parsed=_parse_response(client=client, response=response),
51+
parsed=_parse_response(client=client, response=response), # type: ignore[func-returns-value]
5252
)
5353

5454

end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Non
4848
status_code=HTTPStatus(response.status_code),
4949
content=response.content,
5050
headers=response.headers,
51-
parsed=_parse_response(client=client, response=response),
51+
parsed=_parse_response(client=client, response=response), # type: ignore[func-returns-value]
5252
)
5353

5454

end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Non
6767
status_code=HTTPStatus(response.status_code),
6868
content=response.content,
6969
headers=response.headers,
70-
parsed=_parse_response(client=client, response=response),
70+
parsed=_parse_response(client=client, response=response), # type: ignore[func-returns-value]
7171
)
7272

7373

end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Non
7272
status_code=HTTPStatus(response.status_code),
7373
content=response.content,
7474
headers=response.headers,
75-
parsed=_parse_response(client=client, response=response),
75+
parsed=_parse_response(client=client, response=response), # type: ignore[func-returns-value]
7676
)
7777

7878

end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Non
6060
status_code=HTTPStatus(response.status_code),
6161
content=response.content,
6262
headers=response.headers,
63-
parsed=_parse_response(client=client, response=response),
63+
parsed=_parse_response(client=client, response=response), # type: ignore[func-returns-value]
6464
)
6565

6666

end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Non
4949
status_code=HTTPStatus(response.status_code),
5050
content=response.content,
5151
headers=response.headers,
52-
parsed=_parse_response(client=client, response=response),
52+
parsed=_parse_response(client=client, response=response), # type: ignore[func-returns-value]
5353
)
5454

5555

end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Non
4949
status_code=HTTPStatus(response.status_code),
5050
content=response.content,
5151
headers=response.headers,
52-
parsed=_parse_response(client=client, response=response),
52+
parsed=_parse_response(client=client, response=response), # type: ignore[func-returns-value]
5353
)
5454

5555

end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Non
5757
status_code=HTTPStatus(response.status_code),
5858
content=response.content,
5959
headers=response.headers,
60-
parsed=_parse_response(client=client, response=response),
60+
parsed=_parse_response(client=client, response=response), # type: ignore[func-returns-value]
6161
)
6262

6363

end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Non
4747
status_code=HTTPStatus(response.status_code),
4848
content=response.content,
4949
headers=response.headers,
50-
parsed=_parse_response(client=client, response=response),
50+
parsed=_parse_response(client=client, response=response), # type: ignore[func-returns-value]
5151
)
5252

5353

end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Non
4141
status_code=HTTPStatus(response.status_code),
4242
content=response.content,
4343
headers=response.headers,
44-
parsed=_parse_response(client=client, response=response),
44+
parsed=_parse_response(client=client, response=response), # type: ignore[func-returns-value]
4545
)
4646

4747

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Non
4141
status_code=HTTPStatus(response.status_code),
4242
content=response.content,
4343
headers=response.headers,
44-
parsed=_parse_response(client=client, response=response),
44+
parsed=_parse_response(client=client, response=response), # type: ignore[func-returns-value]
4545
)
4646

4747

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

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

44
import httpx
55

@@ -29,7 +29,7 @@ def _get_kwargs(
2929

3030
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]:
3131
if response.status_code == HTTPStatus.OK:
32-
response_200 = cast(Any, response.json())
32+
response_200 = response.json()
3333
return response_200
3434
if client.raise_on_unexpected_status:
3535
raise errors.UnexpectedStatus(response.status_code, response.content)

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

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

44
import httpx
55

@@ -32,7 +32,7 @@ def _get_kwargs(
3232

3333
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]:
3434
if response.status_code == HTTPStatus.OK:
35-
response_200 = cast(Any, response.json())
35+
response_200 = response.json()
3636
return response_200
3737
if client.raise_on_unexpected_status:
3838
raise errors.UnexpectedStatus(response.status_code, response.content)

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

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

44
import httpx
55

@@ -32,7 +32,7 @@ def _get_kwargs(
3232

3333
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]:
3434
if response.status_code == HTTPStatus.OK:
35-
response_200 = cast(Any, response.json())
35+
response_200 = response.json()
3636
return response_200
3737
if client.raise_on_unexpected_status:
3838
raise errors.UnexpectedStatus(response.status_code, response.content)

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

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

44
import httpx
55

@@ -29,7 +29,7 @@ def _get_kwargs(
2929

3030
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]:
3131
if response.status_code == HTTPStatus.OK:
32-
response_200 = cast(Any, response.json())
32+
response_200 = response.json()
3333
return response_200
3434
if client.raise_on_unexpected_status:
3535
raise errors.UnexpectedStatus(response.status_code, response.content)

end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Non
4848
status_code=HTTPStatus(response.status_code),
4949
content=response.content,
5050
headers=response.headers,
51-
parsed=_parse_response(client=client, response=response),
51+
parsed=_parse_response(client=client, response=response), # type: ignore[func-returns-value]
5252
)
5353

5454

openapi_python_client/templates/endpoint_module.py.jinja

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[{{
8585
status_code=HTTPStatus(response.status_code),
8686
content=response.content,
8787
headers=response.headers,
88+
{% if parsed_responses %}
8889
parsed=_parse_response(client=client, response=response),
90+
{% else %}
91+
{# If _parse_response() returns None, mypy complains: https://github.com/python/mypy/issues/6549 #}
92+
parsed=_parse_response(client=client, response=response), # type: ignore[func-returns-value]
93+
{% endif %}
8994
)
9095

9196

0 commit comments

Comments
 (0)