Skip to content

Commit 263b083

Browse files
authored
fix: Support Python 3.11.0 (#701)
1 parent 30d9f56 commit 263b083

File tree

7 files changed

+240
-136
lines changed

7 files changed

+240
-136
lines changed

.github/workflows/checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
test:
1111
strategy:
1212
matrix:
13-
python: [ "3.7", "3.8", "3.9", "3.10" ]
13+
python: [ "3.7", "3.8", "3.9", "3.10", "3.11" ]
1414
os: [ ubuntu-latest, macos-latest, windows-latest ]
1515
runs-on: ${{ matrix.os }}
1616
steps:

openapi_python_client/parser/properties/property.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def get_imports(self, *, prefix: str) -> Set[str]:
122122
imports.add(f"from {prefix}types import UNSET, Unset")
123123
return imports
124124

125-
# pylint: disable=unused-argument,no-self-use)
125+
# pylint: disable=unused-argument
126126
def get_lazy_imports(self, *, prefix: str) -> Set[str]:
127127
"""Get a set of lazy import strings that should be included when this property is used somewhere
128128
Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
1-
from enum import Enum
1+
# Python 3.11 has StrEnum but breaks the old `str, Enum` hack.
2+
# Unless this gets fixed, we need to have two implementations :(
3+
import sys
24

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

4-
class ParameterLocation(str, Enum):
5-
"""The places Parameters can be put when calling an Endpoint"""
8+
class ParameterLocation(StrEnum):
9+
"""The places Parameters can be put when calling an Endpoint"""
610

7-
QUERY = "query"
8-
PATH = "path"
9-
HEADER = "header"
10-
COOKIE = "cookie"
11+
QUERY = "query"
12+
PATH = "path"
13+
HEADER = "header"
14+
COOKIE = "cookie"
15+
16+
else:
17+
from enum import Enum
18+
19+
class ParameterLocation(str, Enum):
20+
"""The places Parameters can be put when calling an Endpoint"""
21+
22+
QUERY = "query"
23+
PATH = "path"
24+
HEADER = "header"
25+
COOKIE = "cookie"

openapi_python_client/templates/endpoint_module.py.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def _get_kwargs(
6161
{% if parsed_responses %}
6262
def _parse_response(*, response: httpx.Response) -> Optional[{{ return_string }}]:
6363
{% for response in endpoint.responses %}
64-
if response.status_code == {{ response.status_code }}:
64+
if response.status_code == HTTPStatus.{{ response.status_code.name }}:
6565
{% import "property_templates/" + response.prop.template as prop_template %}
6666
{% if prop_template.construct %}
6767
{{ prop_template.construct(response.prop, response.source) | indent(8) }}

0 commit comments

Comments
 (0)