Skip to content

Commit 9546a0e

Browse files
committed
fix: Python 3.8 comptible type hints.
1 parent 431b295 commit 9546a0e

File tree

6 files changed

+16
-15
lines changed

6 files changed

+16
-15
lines changed

openapi_pydantic/compat.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Compatibility layer to make this package usable with Pydantic 1 or 2"""
22

3-
from typing import TYPE_CHECKING, Optional
3+
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple
44

55
from pydantic.version import VERSION as PYDANTIC_VERSION
66

@@ -30,7 +30,7 @@
3030

3131
def ConfigDict(
3232
extra: Literal["allow", "ignore", "forbid"] = "allow",
33-
json_schema_extra: Optional[dict[str, Any]] = None,
33+
json_schema_extra: Optional[Dict[str, Any]] = None,
3434
populate_by_name: bool = True,
3535
) -> PydanticConfigDict:
3636
"""Stub for pydantic.ConfigDict in Pydantic 2"""
@@ -49,21 +49,21 @@ class RootModel(BaseModel):
4949
JsonSchemaMode = Literal["validation", "serialization"]
5050

5151
def models_json_schema(
52-
models: list[tuple[Type[BaseModel], JsonSchemaMode]],
52+
models: List[Tuple[Type[BaseModel], JsonSchemaMode]],
5353
*,
5454
by_alias: bool = True,
5555
ref_template: str = "#/$defs/{model}",
5656
schema_generator: Optional[type] = None,
57-
) -> tuple[dict, dict[str, Any]]:
57+
) -> Tuple[Dict, Dict[str, Any]]:
5858
"""Stub for pydantic.json_schema.models_json_schema in Pydantic 2"""
5959
...
6060

6161
def v1_schema(
62-
models: list[Type[BaseModel]],
62+
models: List[Type[BaseModel]],
6363
*,
6464
by_alias: bool = True,
6565
ref_prefix: str = "#/$defs",
66-
) -> dict[str, Any]:
66+
) -> Dict[str, Any]:
6767
"""Stub for pydantic.schema.schema in Pydantic 1"""
6868
...
6969

openapi_pydantic/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
from typing import Any, Generic, List, Optional, Set, Type, TypeVar, cast
2+
from typing import Any, Dict, Generic, List, Optional, Set, Type, TypeVar, cast
33

44
from pydantic import BaseModel
55

@@ -110,7 +110,7 @@ def construct_open_api_with_schema_class(
110110
return new_open_api
111111

112112

113-
def _validate_schemas(schema_definitions: dict[str, Any]) -> dict[str, Schema]:
113+
def _validate_schemas(schema_definitions: Dict[str, Any]) -> Dict[str, Schema]:
114114
"""Convert JSON Schema definitions to parsed OpenAPI objects"""
115115
# Note: if an error occurs in schema_validate(), it may indicate that
116116
# the generated JSON schemas are not compatible with the version

openapi_pydantic/v3/v3_0_3/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ def schema_validate(
604604
*,
605605
strict: Optional[bool] = None,
606606
from_attributes: Optional[bool] = None,
607-
context: Optional[dict[str, Any]] = None
607+
context: Optional[Dict[str, Any]] = None
608608
) -> Schema:
609609
...
610610

openapi_pydantic/v3/v3_0_3/util.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import (
33
TYPE_CHECKING,
44
Any,
5+
Dict,
56
Generic,
67
List,
78
Optional,
@@ -153,8 +154,8 @@ def construct_open_api_with_schema_class(
153154

154155

155156
def _validate_schemas(
156-
schema_definitions: dict[str, Any]
157-
) -> dict[str, Union[Reference, Schema]]:
157+
schema_definitions: Dict[str, Any]
158+
) -> Dict[str, Union[Reference, Schema]]:
158159
"""Convert JSON Schema definitions to parsed OpenAPI objects"""
159160
# Note: if an error occurs in schema_validate(), it may indicate that
160161
# the generated JSON schemas are not compatible with the version

openapi_pydantic/v3/v3_1_0/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ def schema_validate(
961961
*,
962962
strict: Optional[bool] = None,
963963
from_attributes: Optional[bool] = None,
964-
context: Optional[dict[str, Any]] = None
964+
context: Optional[Dict[str, Any]] = None
965965
) -> Schema:
966966
...
967967

tests/util/test_pydantic_field.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Union
1+
from typing import Any, Dict, Union
22

33
from pydantic import BaseModel, Field
44
from typing_extensions import Literal
@@ -59,8 +59,8 @@ def construct_base_open_api() -> OpenAPI:
5959
def test_pydantic_discriminator_schema_generation() -> None:
6060
"""https://github.com/kuimono/openapi-schema-pydantic/issues/8"""
6161

62-
a_kind: dict[str, Any]
63-
b_kind: dict[str, Any]
62+
a_kind: Dict[str, Any]
63+
b_kind: Dict[str, Any]
6464

6565
if PYDANTIC_V2:
6666
_key_map, json_schema = models_json_schema([(RequestModel, "validation")])

0 commit comments

Comments
 (0)