Skip to content

Commit 3e0a290

Browse files
committed
drop support for python3.9
pyupgrade --py310-plus `git ls-files | grep -E "\.py$"`
1 parent 839a18b commit 3e0a290

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+503
-547
lines changed

aiopenapi3/base.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
import typing
22
import warnings
3-
from typing import Optional, Any, ForwardRef, Union, cast
3+
from typing import Any, ForwardRef, Union, cast
44
from collections.abc import Sequence
55

66
import re
77
import builtins
88
import keyword
99
import uuid
10-
import sys
1110

1211
from pathlib import Path
1312

14-
if sys.version_info >= (3, 10):
15-
from typing import TypeGuard
16-
else:
17-
from typing_extensions import TypeGuard
13+
from typing import TypeGuard
1814

1915
from pydantic import RootModel, BaseModel, TypeAdapter, Field, AnyUrl, model_validator, PrivateAttr, ConfigDict
2016

@@ -37,7 +33,7 @@ class ObjectBase(BaseModel):
3733

3834

3935
class ObjectExtended(ObjectBase):
40-
extensions: Optional[Any] = Field(default=None)
36+
extensions: Any | None = Field(default=None)
4137

4238
@model_validator(mode="before")
4339
def validate_ObjectExtended_extensions(cls, values):
@@ -395,9 +391,9 @@ def _get_identity(self, prefix="XLS", name=None):
395391

396392
def set_type(
397393
self,
398-
names: Optional[list[str]] = None,
399-
discriminators: Optional[Sequence[DiscriminatorBase]] = None,
400-
extra: Optional[list["SchemaBase"]] = None,
394+
names: list[str] | None = None,
395+
discriminators: Sequence[DiscriminatorBase] | None = None,
396+
extra: list["SchemaBase"] | None = None,
401397
) -> type[BaseModel]:
402398
from .model import Model
403399

@@ -418,11 +414,11 @@ def set_type(
418414

419415
def get_type(
420416
self,
421-
names: Optional[list[str]] = None,
422-
discriminators: Optional[Sequence[DiscriminatorBase]] = None,
423-
extra: Optional[list["SchemaBase"]] = None,
417+
names: list[str] | None = None,
418+
discriminators: Sequence[DiscriminatorBase] | None = None,
419+
extra: list["SchemaBase"] | None = None,
424420
fwdref: bool = False,
425-
) -> Union[type[BaseModel], type[TypeAdapter], ForwardRef]:
421+
) -> type[BaseModel] | type[TypeAdapter] | ForwardRef:
426422
if fwdref:
427423
if "module" in ForwardRef.__init__.__code__.co_varnames:
428424
# FIXME Python < 3.9 compat
@@ -436,7 +432,7 @@ def get_type(
436432
else:
437433
return self.set_type(names, discriminators, extra)
438434

439-
def model(self, data: "JSON") -> Union[BaseModel, list[BaseModel]]:
435+
def model(self, data: "JSON") -> BaseModel | list[BaseModel]:
440436
"""
441437
Generates a model representing this schema from the given data.
442438

aiopenapi3/errors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class OperationIdDuplicationError(SpecError):
7272
"""
7373

7474
operationid: str
75-
paths: list[tuple[str, str, object, Optional[list["ServerType"]]]]
75+
paths: list[tuple[str, str, object, list["ServerType"] | None]]
7676

7777

7878
class ParameterFormatError(SpecError):
@@ -129,7 +129,7 @@ class ContentTypeError(ResponseError):
129129
"""The content-type is unexpected"""
130130

131131
operation: "OperationType"
132-
content_type: Optional[str]
132+
content_type: str | None
133133
message: str
134134
response: httpx.Response
135135

@@ -169,7 +169,7 @@ class ResponseSchemaError(ResponseError):
169169
expectation: "ExpectedType"
170170
schema: Optional["SchemaType"]
171171
response: httpx.Response
172-
exception: Optional[Exception]
172+
exception: Exception | None
173173

174174
def __str__(self):
175175
return f"""<{self.__class__.__name__} {self.response.request.method} '{self.response.request.url.path}' ({self.operation.operationId})

aiopenapi3/extra/reduce.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import typing
2-
from typing import Union, Optional
2+
from typing import Union
33
import logging
44
import re
55

@@ -24,7 +24,7 @@ class Context:
2424

2525
def __init__(
2626
self,
27-
*operations: list[Union[tuple["PathMatchType", Optional[list["HTTPMethodMatchType"]]], "OperationIdMatchType"]],
27+
*operations: list[Union[tuple["PathMatchType", list["HTTPMethodMatchType"] | None], "OperationIdMatchType"]],
2828
) -> None:
2929
"""
3030

aiopenapi3/json.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from typing import Union
21
import urllib.parse
32

43
from yarl import URL
@@ -25,7 +24,7 @@ def decode(part: str) -> str:
2524

2625
class JSONReference:
2726
@staticmethod
28-
def split(url: Union[str, URL]) -> tuple[str, str]:
27+
def split(url: str | URL) -> tuple[str, str]:
2928
"""
3029
split the url into path and fragment
3130
"""

aiopenapi3/loader.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import abc
22
import logging
33
import typing
4-
from typing import Optional
54
import yaml
65
import httpx
76
import yarl
@@ -119,7 +118,7 @@ def __init__(self, yload: "YAMLLoaderType" = YAML12Loader):
119118
self.yload = yload
120119

121120
@abc.abstractmethod
122-
def load(self, plugins: Plugins, url: yarl.URL, codec: Optional[str] = None):
121+
def load(self, plugins: Plugins, url: yarl.URL, codec: str | None = None):
123122
"""
124123
load and decode description document
125124
@@ -131,7 +130,7 @@ def load(self, plugins: Plugins, url: yarl.URL, codec: Optional[str] = None):
131130
raise NotImplementedError("load")
132131

133132
@classmethod
134-
def decode(cls, data: bytes, codec: Optional[str]) -> str:
133+
def decode(cls, data: bytes, codec: str | None) -> str:
135134
"""
136135
decode bytes to ascii or utf-8
137136
@@ -203,7 +202,7 @@ class NullLoader(Loader):
203202
Loader does not load anything
204203
"""
205204

206-
def load(self, plugins: Plugins, url: yarl.URL, codec: Optional[str] = None):
205+
def load(self, plugins: Plugins, url: yarl.URL, codec: str | None = None):
207206
raise NotImplementedError("load")
208207

209208

@@ -218,7 +217,7 @@ def __init__(self, baseurl: yarl.URL, session_factory=httpx.Client, yload: "YAML
218217
self.baseurl: yarl.URL = baseurl
219218
self.session_factory = session_factory
220219

221-
def load(self, plugins: Plugins, url: yarl.URL, codec: Optional[str] = None) -> "JSON":
220+
def load(self, plugins: Plugins, url: yarl.URL, codec: str | None = None) -> "JSON":
222221
url = self.baseurl.join(url)
223222
with self.session_factory() as session:
224223
data = session.get(str(url))
@@ -246,7 +245,7 @@ def __init__(self, base: Path, yload: "YAMLLoaderType" = YAML12Loader):
246245
assert isinstance(base, Path)
247246
self.base = base
248247

249-
def load(self, plugins: Plugins, url: yarl.URL, codec: Optional[str] = None):
248+
def load(self, plugins: Plugins, url: yarl.URL, codec: str | None = None):
250249
assert isinstance(url, yarl.URL)
251250
assert plugins
252251
file = Path(url.path)
@@ -269,7 +268,7 @@ class RedirectLoader(FileSystemLoader):
269268
everything but the "name" is stripped of the url
270269
"""
271270

272-
def load(self, plugins: "Plugins", url: yarl.URL, codec: Optional[str] = None):
271+
def load(self, plugins: "Plugins", url: yarl.URL, codec: str | None = None):
273272
return super().load(plugins, yarl.URL(url.name), codec)
274273

275274

@@ -287,7 +286,7 @@ def __init__(self, *loaders, yload: "YAMLLoaderType" = YAML12Loader):
287286
Loader.__init__(self, yload)
288287
self.loaders = loaders
289288

290-
def load(self, plugins: "Plugins", url: yarl.URL, codec: Optional[str] = None):
289+
def load(self, plugins: "Plugins", url: yarl.URL, codec: str | None = None):
291290
log.debug(f"load {url}")
292291
errors = []
293292
for i in self.loaders:

aiopenapi3/log.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import sys
22
import logging.config
33
import os
4-
from typing import Any, Optional
4+
from typing import Any
55

66
from pathlib import Path
77

8-
handlers: Optional[list[str]] = None
8+
handlers: list[str] | None = None
99

1010

1111
def init(force: bool = False) -> None:

aiopenapi3/model.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
from typing import Any, cast, TypeVar
88
import typing
99

10-
if sys.version_info >= (3, 10):
11-
from typing import TypeGuard
12-
else:
13-
from typing_extensions import TypeGuard
10+
from typing import TypeGuard
1411

1512
from typing import Optional, Union, Annotated, Literal
1613
from pydantic import BaseModel, TypeAdapter, Field, RootModel, ConfigDict
@@ -24,7 +21,7 @@
2421
from .base import DiscriminatorBase
2522
from ._types import SchemaType, ReferenceType, PrimitiveTypes, DiscriminatorType
2623

27-
type_format_to_class: dict[str, dict[Optional[str], type]] = collections.defaultdict(dict)
24+
type_format_to_class: dict[str, dict[str | None, type]] = collections.defaultdict(dict)
2825

2926
log = logging.getLogger("aiopenapi3.model")
3027

@@ -135,7 +132,7 @@ def createFields(self, schema: "SchemaType", overwrite=False):
135132
return
136133

137134
if Model.is_type(schema, "object") or Model.is_type_any(schema):
138-
f: Union[SchemaBase, ReferenceBase]
135+
f: SchemaBase | ReferenceBase
139136
assert schema.properties is not None
140137
for name, f in schema.properties.items():
141138
if (
@@ -236,7 +233,7 @@ def _createAnnotations(
236233
raise ValueError()
237234
return
238235

239-
def model(self) -> Union[type[BaseModel], type[None]]:
236+
def model(self) -> type[BaseModel] | type[None]:
240237
if self.root:
241238
m = self.root
242239
else:
@@ -253,7 +250,7 @@ def model(self) -> Union[type[BaseModel], type[None]]:
253250

254251
@classmethod
255252
def collapse(cls, type_name, items: list["_ClassInfo"]) -> type[BaseModel]:
256-
r: list[Union[type[BaseModel], type[None]]]
253+
r: list[type[BaseModel] | type[None]]
257254

258255
r = [i.model() for i in items]
259256

@@ -287,9 +284,9 @@ class Model: # (BaseModel):
287284
def from_schema(
288285
cls,
289286
schema: "SchemaType",
290-
schemanames: Optional[list[str]] = None,
291-
discriminators: Optional[list["DiscriminatorType"]] = None,
292-
extra: Optional[list["SchemaType"]] = None,
287+
schemanames: list[str] | None = None,
288+
discriminators: list["DiscriminatorType"] | None = None,
289+
extra: list["SchemaType"] | None = None,
293290
) -> type[BaseModel]:
294291
if schemanames is None:
295292
schemanames = []
@@ -313,7 +310,7 @@ def createClassInfo(
313310
_type: str,
314311
schemanames: list[str],
315312
discriminators: list["DiscriminatorType"],
316-
extra: Optional[list["SchemaType"]],
313+
extra: list["SchemaType"] | None,
317314
) -> _ClassInfo:
318315
from . import v20, v30, v31
319316

@@ -504,7 +501,7 @@ def createConfigDict(schema: "SchemaType"):
504501

505502
@staticmethod
506503
def createAnnotation(
507-
schema: Optional[Union["SchemaType", "ReferenceType"]], _type: Optional[str] = None, fwdref: bool = False
504+
schema: Union["SchemaType", "ReferenceType"] | None, _type: str | None = None, fwdref: bool = False
508505
) -> type:
509506
if schema is None:
510507
return BaseModel
@@ -662,7 +659,7 @@ def is_type(schema: "SchemaType", type_) -> bool:
662659
return isinstance(schema.type, str) and schema.type == type_ or Model.or_type(schema, type_, l=None)
663660

664661
@staticmethod
665-
def or_type(schema: "SchemaType", type_: str, l: Optional[int] = 2) -> bool:
662+
def or_type(schema: "SchemaType", type_: str, l: int | None = 2) -> bool:
666663
return isinstance((t := schema.type), list) and (l is None or len(t) == l) and type_ in t
667664

668665
@staticmethod

aiopenapi3/models/epoch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from __future__ import annotations
22

33
import datetime
4-
from typing import Any, Callable
4+
from typing import Any
5+
from collections.abc import Callable
56

67
import pydantic_core.core_schema
78
from pydantic import GetJsonSchemaHandler

0 commit comments

Comments
 (0)