Skip to content

Commit 0b508da

Browse files
committed
fix: Work around Enum breaking changes in 3.11.0
1 parent 4e37789 commit 0b508da

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed
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) }}

tests/test_parser/test_openapi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from openapi_python_client.parser.errors import ParseError
99
from openapi_python_client.parser.openapi import Endpoint, EndpointCollection
1010
from openapi_python_client.parser.properties import IntProperty, Parameters, Schemas
11+
from openapi_python_client.schema import ParameterLocation
1112

1213
MODULE_NAME = "openapi_python_client.parser.openapi"
1314

0 commit comments

Comments
 (0)