Skip to content

Commit 0f8a3cd

Browse files
committed
⬆️ remove Python 3.8 support
1 parent 0b7f1ab commit 0f8a3cd

File tree

9 files changed

+1078
-881
lines changed

9 files changed

+1078
-881
lines changed

nonebot_plugin_orm/__init__.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
from __future__ import annotations
22

3-
import sys
43
import logging
5-
from typing import Any
64
from argparse import Namespace
75
from functools import wraps, lru_cache
6+
from typing_extensions import Any, Annotated
87

98
import click
109
from nonebot.rule import Rule
@@ -25,11 +24,6 @@
2524
from .config import Config, plugin_config
2625
from .utils import LoguruHandler, StreamToLogger, coroutine, get_subclasses
2726

28-
if sys.version_info >= (3, 9):
29-
from typing import Annotated
30-
else:
31-
from typing_extensions import Annotated
32-
3327
require("nonebot_plugin_localstore")
3428
from nonebot_plugin_localstore import get_data_dir
3529

nonebot_plugin_orm/__main__.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from __future__ import annotations
22

3-
import sys
43
from pathlib import Path
5-
from typing import TypeVar
64
from functools import wraps
75
from argparse import Namespace
86
from collections.abc import Callable, Iterable
7+
from typing_extensions import TypeVar, ParamSpec, Concatenate
98

109
import click
1110
from alembic.script import Script
@@ -14,11 +13,6 @@
1413
from .config import plugin_config
1514
from .migrate import AlembicConfig
1615

17-
if sys.version_info >= (3, 10):
18-
from typing import ParamSpec, Concatenate
19-
else:
20-
from typing_extensions import ParamSpec, Concatenate
21-
2216
_P = ParamSpec("_P")
2317
_R = TypeVar("_R")
2418

nonebot_plugin_orm/config.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
from pathlib import Path
32
from typing import Any, Union, Optional
43

@@ -9,11 +8,6 @@
98

109
from .migrate import AlembicConfig
1110

12-
if sys.version_info >= (3, 9):
13-
Dict = dict
14-
else:
15-
from typing import Dict
16-
1711
__all__ = (
1812
"Config",
1913
"plugin_config",
@@ -22,15 +16,15 @@
2216

2317
class Config(BaseModel, arbitrary_types_allowed=True):
2418
sqlalchemy_database_url: Union[str, URL, AsyncEngine] = ""
25-
sqlalchemy_binds: Dict[str, Union[str, URL, Dict[str, Any], AsyncEngine]] = {}
19+
sqlalchemy_binds: dict[str, Union[str, URL, dict[str, Any], AsyncEngine]] = {}
2620
sqlalchemy_echo: bool = False
27-
sqlalchemy_engine_options: Dict[str, Any] = {}
28-
sqlalchemy_session_options: Dict[str, Any] = {}
21+
sqlalchemy_engine_options: dict[str, Any] = {}
22+
sqlalchemy_session_options: dict[str, Any] = {}
2923

3024
alembic_config: Union[Path, AlembicConfig, None] = None
3125
alembic_script_location: Optional[Path] = None
32-
alembic_version_locations: Union[Path, Dict[str, Path], None] = None
33-
alembic_context: Dict[str, Any] = {}
26+
alembic_version_locations: Union[Path, dict[str, Path], None] = None
27+
alembic_context: dict[str, Any] = {}
3428
alembic_startup_check: bool = True
3529

3630

nonebot_plugin_orm/migrate.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
from argparse import Namespace
1010
from operator import attrgetter
1111
from itertools import filterfalse
12-
from typing import Any, TextIO, cast
1312
from tempfile import TemporaryDirectory
1413
from configparser import DuplicateSectionError
14+
from typing_extensions import Any, Self, TextIO, cast
1515
from contextlib import ExitStack, suppress, contextmanager
1616
from collections.abc import Mapping, Iterable, Sequence, Generator
1717

@@ -37,11 +37,6 @@
3737
from .exception import AutogenerateDiffsDetected
3838
from .utils import is_editable, get_parent_plugins, return_progressbar
3939

40-
if sys.version_info >= (3, 11):
41-
from typing import Self
42-
else:
43-
from typing_extensions import Self
44-
4540
if sys.version_info >= (3, 12):
4641
from importlib.resources import files, as_file
4742
else:

nonebot_plugin_orm/model.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
from __future__ import annotations
22

3-
import sys
43
from inspect import Parameter, Signature
5-
from typing import TYPE_CHECKING, Any, ClassVar
4+
from typing_extensions import (
5+
TYPE_CHECKING,
6+
Any,
7+
ClassVar,
8+
Annotated,
9+
get_args,
10+
get_origin,
11+
get_annotations,
12+
)
613

714
from sqlalchemy import Table, MetaData
815
from nonebot import get_plugin_by_module_name
916
from sqlalchemy.orm import Mapped, DeclarativeBase
1017

11-
from .utils import DependsInner, get_annotations
12-
13-
if sys.version_info >= (3, 10):
14-
from typing import Annotated, get_args, get_origin
15-
else:
16-
from typing_extensions import Annotated, get_args, get_origin
18+
from .utils import DependsInner
1719

1820
__all__ = ("Model",)
1921

nonebot_plugin_orm/param.py

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from __future__ import annotations
22

3-
import sys
4-
from itertools import repeat
5-
from typing import Any, cast
63
from dataclasses import dataclass
74
from operator import methodcaller
85
from inspect import Parameter, isclass
6+
from collections.abc import Iterator, Sequence, AsyncIterator
7+
from typing_extensions import Any, Self, Annotated, cast, get_args, get_origin
98

109
from pydantic.fields import FieldInfo
1110
from nonebot.dependencies import Param
@@ -18,29 +17,19 @@
1817
from .model import Model
1918
from .utils import Option, Dependency, generic_issubclass
2019

21-
if sys.version_info >= (3, 11):
22-
from typing import Annotated, get_args, get_origin
23-
from collections.abc import Iterator, Sequence, AsyncIterator
24-
25-
Tuple = tuple
26-
Type = type
27-
else:
28-
from typing_extensions import Annotated, get_args, get_origin
29-
from typing import Type, Tuple, Iterator, Sequence, AsyncIterator
30-
3120
__all__ = (
3221
"SQLDepends",
3322
"ORMParam",
3423
)
3524

3625

3726
PATTERNS = {
38-
AsyncIterator[Sequence[Row[Tuple[Any, ...]]]]: Option(
27+
AsyncIterator[Sequence[Row[tuple[Any, ...]]]]: Option(
3928
True,
4029
False,
4130
(methodcaller("partitions"),),
4231
),
43-
AsyncIterator[Sequence[Tuple[Any, ...]]]: Option(
32+
AsyncIterator[Sequence[tuple[Any, ...]]]: Option(
4433
True,
4534
False,
4635
(methodcaller("partitions"),),
@@ -50,12 +39,12 @@
5039
True,
5140
(methodcaller("partitions"),),
5241
),
53-
Iterator[Sequence[Row[Tuple[Any, ...]]]]: Option(
42+
Iterator[Sequence[Row[tuple[Any, ...]]]]: Option(
5443
False,
5544
False,
5645
(methodcaller("partitions"),),
5746
),
58-
Iterator[Sequence[Tuple[Any, ...]]]: Option(
47+
Iterator[Sequence[tuple[Any, ...]]]: Option(
5948
False,
6049
False,
6150
(methodcaller("partitions"),),
@@ -65,37 +54,37 @@
6554
True,
6655
(methodcaller("partitions"),),
6756
),
68-
AsyncResult[Tuple[Any, ...]]: Option(
57+
AsyncResult[tuple[Any, ...]]: Option(
6958
True,
7059
False,
7160
),
7261
AsyncScalarResult[Any]: Option(
7362
True,
7463
True,
7564
),
76-
Result[Tuple[Any, ...]]: Option(
65+
Result[tuple[Any, ...]]: Option(
7766
False,
7867
False,
7968
),
8069
ScalarResult[Any]: Option(
8170
False,
8271
True,
8372
),
84-
AsyncIterator[Row[Tuple[Any, ...]]]: Option(
73+
AsyncIterator[Row[tuple[Any, ...]]]: Option(
8574
True,
8675
False,
8776
),
88-
Iterator[Row[Tuple[Any, ...]]]: Option(
77+
Iterator[Row[tuple[Any, ...]]]: Option(
8978
False,
9079
False,
9180
),
92-
Sequence[Row[Tuple[Any, ...]]]: Option(
81+
Sequence[Row[tuple[Any, ...]]]: Option(
9382
True,
9483
False,
9584
(),
9685
methodcaller("all"),
9786
),
98-
Sequence[Tuple[Any, ...]]: Option(
87+
Sequence[tuple[Any, ...]]: Option(
9988
True,
10089
False,
10190
(),
@@ -107,7 +96,7 @@
10796
(),
10897
methodcaller("all"),
10998
),
110-
Tuple[Any, ...]: Option(
99+
tuple[Any, ...]: Option(
111100
True,
112101
False,
113102
(),
@@ -142,7 +131,7 @@ class ORMParam(DependParam):
142131
@classmethod
143132
def _check_param(
144133
cls, param: Parameter, allow_types: tuple[type[Param], ...]
145-
) -> Param | None:
134+
) -> Self | None:
146135
type_annotation, depends_inner = param.annotation, None
147136
if get_origin(param.annotation) is Annotated:
148137
type_annotation, *extra_args = get_args(param.annotation)
@@ -205,5 +194,7 @@ def _check_param(
205194
)
206195

207196
@classmethod
208-
def _check_parameterless(cls, *_) -> None:
197+
def _check_parameterless(
198+
cls, value: Any, allow_types: tuple[type[Param], ...]
199+
) -> None:
209200
return

0 commit comments

Comments
 (0)