Skip to content

feat!: Change the Response.status_code type to the HTTPStatus enum #665

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 9 commits into from
Sep 18, 2022
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
## Setting up a Dev Environment

1. Make sure you have [Poetry](https://python-poetry.org/) installed and up to date.
2. Make sure you have a supported Python version (e.g. 3.8) installed and accessible to Poetry (e.g. with [pyenv](https://github.com/pyenv/pyenv).
2. Make sure you have a supported Python version (e.g. 3.8) installed and accessible to Poetry (e.g. with [pyenv](https://github.com/pyenv/pyenv)).
3. Use `poetry install` in the project directory to create a virtual environment with the relevant dependencies.
4. Enter a `poetry shell` to make running commands easier.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from http import HTTPStatus
from typing import Any, Dict, Union

import httpx
Expand Down Expand Up @@ -33,7 +34,7 @@ def _get_kwargs(

def _build_response(*, response: httpx.Response) -> Response[Any]:
return Response(
status_code=response.status_code,
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=None,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from http import HTTPStatus
from typing import Any, Dict, Union

import httpx
Expand Down Expand Up @@ -33,7 +34,7 @@ def _get_kwargs(

def _build_response(*, response: httpx.Response) -> Response[Any]:
return Response(
status_code=response.status_code,
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=None,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from http import HTTPStatus
from typing import Any, Dict, Union

import httpx
Expand Down Expand Up @@ -52,7 +53,7 @@ def _get_kwargs(

def _build_response(*, response: httpx.Response) -> Response[Any]:
return Response(
status_code=response.status_code,
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=None,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
from http import HTTPStatus
from typing import Any, Dict, Union

import httpx
Expand Down Expand Up @@ -57,7 +58,7 @@ def _get_kwargs(

def _build_response(*, response: httpx.Response) -> Response[Any]:
return Response(
status_code=response.status_code,
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=None,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from http import HTTPStatus
from typing import Any, Dict

import httpx
Expand Down Expand Up @@ -43,7 +44,7 @@ def _get_kwargs(

def _build_response(*, response: httpx.Response) -> Response[Any]:
return Response(
status_code=response.status_code,
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=None,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from http import HTTPStatus
from typing import Any, Dict, Union

import httpx
Expand Down Expand Up @@ -34,7 +35,7 @@ def _get_kwargs(

def _build_response(*, response: httpx.Response) -> Response[Any]:
return Response(
status_code=response.status_code,
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=None,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from http import HTTPStatus
from typing import Any, Dict

import httpx
Expand Down Expand Up @@ -34,7 +35,7 @@ def _get_kwargs(

def _build_response(*, response: httpx.Response) -> Response[Any]:
return Response(
status_code=response.status_code,
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=None,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from http import HTTPStatus
from typing import Any, Dict, Union

import httpx
Expand Down Expand Up @@ -42,7 +43,7 @@ def _get_kwargs(

def _build_response(*, response: httpx.Response) -> Response[Any]:
return Response(
status_code=response.status_code,
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=None,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from http import HTTPStatus
from typing import Any, Dict

import httpx
Expand Down Expand Up @@ -32,7 +33,7 @@ def _get_kwargs(

def _build_response(*, response: httpx.Response) -> Response[Any]:
return Response(
status_code=response.status_code,
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=None,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from http import HTTPStatus
from typing import Any, Dict, Optional

import httpx
Expand Down Expand Up @@ -28,7 +29,7 @@ def _get_kwargs(


def _parse_response(*, response: httpx.Response) -> Optional[PostResponsesUnionsSimpleBeforeComplexResponse200]:
if response.status_code == 200:
if response.status_code == HTTPStatus.OK:
response_200 = PostResponsesUnionsSimpleBeforeComplexResponse200.from_dict(response.json())

return response_200
Expand All @@ -37,7 +38,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[PostResponsesUnions

def _build_response(*, response: httpx.Response) -> Response[PostResponsesUnionsSimpleBeforeComplexResponse200]:
return Response(
status_code=response.status_code,
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from http import HTTPStatus
from typing import Any, Dict

import httpx
Expand Down Expand Up @@ -26,7 +27,7 @@ def _get_kwargs(

def _build_response(*, response: httpx.Response) -> Response[Any]:
return Response(
status_code=response.status_code,
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=None,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from http import HTTPStatus
from typing import Any, Dict, Optional, Union, cast

import httpx
Expand Down Expand Up @@ -31,10 +32,10 @@ def _get_kwargs(


def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]:
if response.status_code == 200:
if response.status_code == HTTPStatus.OK:
response_200 = cast(Any, response.json())
return response_200
if response.status_code == 422:
if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY:
response_422 = HTTPValidationError.from_dict(response.json())

return response_422
Expand All @@ -43,7 +44,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPVali

def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]:
return Response(
status_code=response.status_code,
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
from http import HTTPStatus
from typing import Any, Dict, List, Optional, Union, cast

import httpx
Expand Down Expand Up @@ -98,10 +99,10 @@ def _get_kwargs(


def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]:
if response.status_code == 200:
if response.status_code == HTTPStatus.OK:
response_200 = cast(Any, response.json())
return response_200
if response.status_code == 422:
if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY:
response_422 = HTTPValidationError.from_dict(response.json())

return response_422
Expand All @@ -110,7 +111,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPVali

def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]:
return Response(
status_code=response.status_code,
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from http import HTTPStatus
from typing import Any, Dict, List, Optional, cast

import httpx
Expand Down Expand Up @@ -25,7 +26,7 @@ def _get_kwargs(


def _parse_response(*, response: httpx.Response) -> Optional[List[bool]]:
if response.status_code == 200:
if response.status_code == HTTPStatus.OK:
response_200 = cast(List[bool], response.json())

return response_200
Expand All @@ -34,7 +35,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[List[bool]]:

def _build_response(*, response: httpx.Response) -> Response[List[bool]]:
return Response(
status_code=response.status_code,
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from http import HTTPStatus
from typing import Any, Dict, List, Optional, cast

import httpx
Expand Down Expand Up @@ -25,7 +26,7 @@ def _get_kwargs(


def _parse_response(*, response: httpx.Response) -> Optional[List[float]]:
if response.status_code == 200:
if response.status_code == HTTPStatus.OK:
response_200 = cast(List[float], response.json())

return response_200
Expand All @@ -34,7 +35,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[List[float]]:

def _build_response(*, response: httpx.Response) -> Response[List[float]]:
return Response(
status_code=response.status_code,
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from http import HTTPStatus
from typing import Any, Dict, List, Optional, cast

import httpx
Expand Down Expand Up @@ -25,7 +26,7 @@ def _get_kwargs(


def _parse_response(*, response: httpx.Response) -> Optional[List[int]]:
if response.status_code == 200:
if response.status_code == HTTPStatus.OK:
response_200 = cast(List[int], response.json())

return response_200
Expand All @@ -34,7 +35,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[List[int]]:

def _build_response(*, response: httpx.Response) -> Response[List[int]]:
return Response(
status_code=response.status_code,
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from http import HTTPStatus
from typing import Any, Dict, List, Optional, cast

import httpx
Expand Down Expand Up @@ -25,7 +26,7 @@ def _get_kwargs(


def _parse_response(*, response: httpx.Response) -> Optional[List[str]]:
if response.status_code == 200:
if response.status_code == HTTPStatus.OK:
response_200 = cast(List[str], response.json())

return response_200
Expand All @@ -34,7 +35,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[List[str]]:

def _build_response(*, response: httpx.Response) -> Response[List[str]]:
return Response(
status_code=response.status_code,
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
from http import HTTPStatus
from typing import Any, Dict, List, Optional, Union

import httpx
Expand Down Expand Up @@ -69,7 +70,7 @@ def _get_kwargs(


def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidationError, List[AModel]]]:
if response.status_code == 200:
if response.status_code == HTTPStatus.OK:
response_200 = []
_response_200 = response.json()
for response_200_item_data in _response_200:
Expand All @@ -78,11 +79,11 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidatio
response_200.append(response_200_item)

return response_200
if response.status_code == 422:
if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY:
response_422 = HTTPValidationError.from_dict(response.json())

return response_422
if response.status_code == 423:
if response.status_code == HTTPStatus.LOCKED:
response_423 = HTTPValidationError.from_dict(response.json())

return response_423
Expand All @@ -91,7 +92,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidatio

def _build_response(*, response: httpx.Response) -> Response[Union[HTTPValidationError, List[AModel]]]:
return Response(
status_code=response.status_code,
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from http import HTTPStatus
from typing import Any, Dict, Optional, Union, cast

import httpx
Expand Down Expand Up @@ -36,10 +37,10 @@ def _get_kwargs(


def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]:
if response.status_code == 200:
if response.status_code == HTTPStatus.OK:
response_200 = cast(Any, response.json())
return response_200
if response.status_code == 422:
if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY:
response_422 = HTTPValidationError.from_dict(response.json())

return response_422
Expand All @@ -48,7 +49,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPVali

def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]:
return Response(
status_code=response.status_code,
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
Expand Down
Loading