Skip to content

fix: Support Python 3.11.0 #701

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 7 commits into from
Dec 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
test:
strategy:
matrix:
python: [ "3.7", "3.8", "3.9", "3.10" ]
python: [ "3.7", "3.8", "3.9", "3.10", "3.11" ]
os: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion openapi_python_client/parser/properties/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def get_imports(self, *, prefix: str) -> Set[str]:
imports.add(f"from {prefix}types import UNSET, Unset")
return imports

# pylint: disable=unused-argument,no-self-use)
# pylint: disable=unused-argument
def get_lazy_imports(self, *, prefix: str) -> Set[str]:
"""Get a set of lazy import strings that should be included when this property is used somewhere

Expand Down
29 changes: 22 additions & 7 deletions openapi_python_client/schema/parameter_location.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
from enum import Enum
# Python 3.11 has StrEnum but breaks the old `str, Enum` hack.
# Unless this gets fixed, we need to have two implementations :(
import sys

if sys.version_info >= (3, 11):
from enum import StrEnum

class ParameterLocation(str, Enum):
"""The places Parameters can be put when calling an Endpoint"""
class ParameterLocation(StrEnum):
"""The places Parameters can be put when calling an Endpoint"""

QUERY = "query"
PATH = "path"
HEADER = "header"
COOKIE = "cookie"
QUERY = "query"
PATH = "path"
HEADER = "header"
COOKIE = "cookie"

else:
from enum import Enum

class ParameterLocation(str, Enum):
"""The places Parameters can be put when calling an Endpoint"""

QUERY = "query"
PATH = "path"
HEADER = "header"
COOKIE = "cookie"
2 changes: 1 addition & 1 deletion openapi_python_client/templates/endpoint_module.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _get_kwargs(
{% if parsed_responses %}
def _parse_response(*, response: httpx.Response) -> Optional[{{ return_string }}]:
{% for response in endpoint.responses %}
if response.status_code == {{ response.status_code }}:
if response.status_code == HTTPStatus.{{ response.status_code.name }}:
{% import "property_templates/" + response.prop.template as prop_template %}
{% if prop_template.construct %}
{{ prop_template.construct(response.prop, response.source) | indent(8) }}
Expand Down
Loading