Skip to content

Commit 8cff225

Browse files
committed
mypy - TypeGuard is python 3.10
1 parent 66e4cd7 commit 8cff225

File tree

6 files changed

+45
-21
lines changed

6 files changed

+45
-21
lines changed

aiopenapi3/base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import typing
22
import warnings
3-
from typing import Optional, Any, List, Dict, ForwardRef, Union, Tuple, cast, Type, TypeGuard, FrozenSet, Sequence
3+
from typing import Optional, Any, List, Dict, ForwardRef, Union, Tuple, cast, Type, FrozenSet, Sequence
44

55
import re
66
import builtins
@@ -13,6 +13,11 @@
1313
else:
1414
from pathlib3x import Path
1515

16+
if sys.version_info >= (3, 10):
17+
from typing import TypeGuard
18+
else:
19+
from typing_extensions import TypeGuard
20+
1621
from pydantic import BaseModel, Field, AnyUrl, model_validator, PrivateAttr, ConfigDict
1722

1823
from .json import JSONPointer, JSONReference

aiopenapi3/model.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,13 @@
55
import logging
66
import re
77
import sys
8-
from typing import Any, Set, Type, cast, TypeGuard, TypeVar
8+
from typing import Any, Set, Type, cast, TypeVar
99
import typing
1010

11-
import pydantic
12-
13-
if sys.version_info >= (3, 9):
14-
pass
11+
if sys.version_info >= (3, 10):
12+
from typing import TypeGuard
1513
else:
16-
from pathlib3x import Path
17-
18-
19-
from .base import ReferenceBase, SchemaBase
20-
from . import me
21-
from .pydanticv2 import field_class_to_schema
14+
from typing_extensions import TypeGuard
2215

2316
if sys.version_info >= (3, 9):
2417
from typing import List, Optional, Union, Tuple, Dict, Annotated, Literal
@@ -27,6 +20,11 @@
2720
from typing_extensions import Annotated, Literal
2821

2922
from pydantic import BaseModel, Field, RootModel, ConfigDict
23+
import pydantic
24+
25+
from .base import ReferenceBase, SchemaBase
26+
from . import me
27+
from .pydanticv2 import field_class_to_schema
3028

3129
if typing.TYPE_CHECKING:
3230
from .base import DiscriminatorBase

aiopenapi3/openapi.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
import sys
22
import typing
33

4-
if sys.version_info >= (3, 9):
5-
import pathlib
6-
else:
7-
import pathlib3x as pathlib
8-
9-
from typing import List, Dict, Set, Callable, Tuple, Any, Union, cast, Optional, TypeGuard, Type, ForwardRef
4+
from typing import List, Dict, Set, Callable, Tuple, Any, Union, cast, Optional, Type, ForwardRef
105
import collections
116
import inspect
127
import logging
138
import copy
149
import pickle
1510

11+
if sys.version_info >= (3, 9):
12+
import pathlib
13+
else:
14+
import pathlib3x as pathlib
15+
16+
17+
if sys.version_info >= (3, 10):
18+
from typing import TypeGuard
19+
else:
20+
from typing_extensions import TypeGuard
21+
22+
1623
import httpx
1724
import yarl
1825
from pydantic import BaseModel

aiopenapi3/plugin.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
import typing
33
from typing import TYPE_CHECKING, List, Any, Dict, Optional, Type
44
import abc
5+
import sys
6+
7+
if sys.version_info >= (3, 10):
8+
from typing import TypeGuard
9+
else:
10+
from typing_extensions import TypeGuard
11+
512

613
from pydantic import BaseModel
714

@@ -194,7 +201,7 @@ def _get_domain(self, name: str, plugins: List[Plugin]) -> "Domain":
194201
if (domain := self._domains.get(name)) is None:
195202
raise ValueError(name) # noqa
196203

197-
def domain_type_f(p: Plugin) -> typing.TypeGuard[Plugin]:
204+
def domain_type_f(p: Plugin) -> TypeGuard[Plugin]:
198205
return isinstance(p, domain)
199206

200207
p: List[Plugin] = list(filter(domain_type_f, plugins))

aiopenapi3/v20/glue.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import typing
2-
from typing import List, Union, cast, Tuple, Dict, Optional, TypeGuard, Sequence
2+
from typing import List, Union, cast, Tuple, Dict, Optional, Sequence
33
import json
4+
import sys
5+
6+
if sys.version_info >= (3, 10):
7+
from typing import TypeGuard
8+
else:
9+
from typing_extensions import TypeGuard
10+
411

512
import httpx
613
import pydantic

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dependencies = [
1111
"yarl==1.8.1",
1212
"httpx",
1313
"more-itertools",
14-
'typing_extensions; python_version<"3.9"',
14+
'typing_extensions; python_version<"3.10"',
1515
'pathlib3x; python_version<"3.9"',
1616
"jmespath",
1717
]

0 commit comments

Comments
 (0)