Skip to content

Commit 4abc83c

Browse files
committed
Revert ":arrow_up: ruff check and format"
This reverts commit 329f1ff. chore: Lower asgiref dependency minimum and add Python 3.9 to Codecov CI matrix. chore: adjust project configuration in pyproject.toml chore: Downgrade nonebot2 to 2.3.0 and remove anyio and exceptiongroup dependencies.
1 parent 115ff4b commit 4abc83c

16 files changed

Lines changed: 503 additions & 98 deletions

File tree

.github/workflows/codecov.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
15+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
1616

1717
steps:
1818
- uses: actions/checkout@v6

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repos:
1010
rev: v0.14.6
1111
hooks:
1212
- id: ruff-check
13-
args: [--fix, --exit-non-zero-on-fix]
13+
args: [--fix]
1414
stages: [pre-commit]
1515
- id: ruff-format
1616
stages: [pre-commit]

nonebug/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Optional
12
import contextlib
23
from typing_extensions import Self
34

@@ -36,7 +37,7 @@ def __init__(self):
3637

3738
from .provider import NoneBugProvider
3839

39-
self.context: Context | None = None
40+
self.context: Optional[Context] = None
4041
if not isinstance(matchers.provider, NoneBugProvider): # pragma: no cover
4142
raise RuntimeError("NoneBug is not initialized")
4243
self.provider = matchers.provider

nonebug/mixin/call_api/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ def create_adapter(
5151
def create_adapter(
5252
self,
5353
*,
54-
base: type[A] | None = None,
54+
base: Optional[type[A]] = None,
5555
**kwargs: Any,
5656
) -> A: ...
5757

5858
def create_adapter(
5959
self,
6060
*,
61-
base: type[A] | None = None,
61+
base: Optional[type[A]] = None,
6262
**kwargs: Any,
6363
) -> Union[A, "Adapter"]:
6464
from nonebot import get_driver
@@ -80,7 +80,7 @@ def create_bot(
8080
def create_bot(
8181
self,
8282
*,
83-
base: type[B] | None = None,
83+
base: Optional[type[B]] = None,
8484
adapter: Optional["Adapter"] = None,
8585
self_id: str = "test",
8686
auto_connect: bool = True,
@@ -90,7 +90,7 @@ def create_bot(
9090
def create_bot(
9191
self,
9292
*,
93-
base: type[B] | None = None,
93+
base: Optional[type[B]] = None,
9494
adapter: Optional["Adapter"] = None,
9595
self_id: str = "test",
9696
auto_connect: bool = True,
@@ -116,8 +116,8 @@ def should_call_api(
116116
self,
117117
api: str,
118118
data: dict[str, Any],
119-
result: Any | None = None,
120-
exception: Exception | None = None,
119+
result: Optional[Any] = None,
120+
exception: Optional[Exception] = None,
121121
adapter: Optional["Adapter"] = None,
122122
) -> Api:
123123
model = Api(
@@ -130,8 +130,8 @@ def should_call_send(
130130
self,
131131
event: "Event",
132132
message: Union[str, "Message", "MessageSegment"],
133-
result: Any | None = None,
134-
exception: Exception | None = None,
133+
result: Optional[Any] = None,
134+
exception: Optional[Exception] = None,
135135
bot: Optional["Bot"] = None,
136136
**kwargs: Any,
137137
) -> Send:

nonebug/mixin/call_api/fake.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TYPE_CHECKING, Any, Union, TypeVar, overload
1+
from typing import TYPE_CHECKING, Any, Union, TypeVar, Optional, overload
22
from typing_extensions import override
33

44
if TYPE_CHECKING:
@@ -19,7 +19,9 @@ def make_fake_adapter(ctx: "ApiContext", base: A) -> A: ...
1919

2020

2121
# fake class should be created every init
22-
def make_fake_adapter(ctx: "ApiContext", base: A | None = None) -> A | type["Adapter"]:
22+
def make_fake_adapter(
23+
ctx: "ApiContext", base: Optional[A] = None
24+
) -> Union[A, type["Adapter"]]:
2325
from nonebot.adapters import Adapter
2426

2527
_base = base or Adapter
@@ -45,7 +47,7 @@ def make_fake_bot(ctx: "ApiContext", base: None = None) -> type["Bot"]: ...
4547
def make_fake_bot(ctx: "ApiContext", base: B) -> B: ...
4648

4749

48-
def make_fake_bot(ctx: "ApiContext", base: B | None = None) -> B | type["Bot"]:
50+
def make_fake_bot(ctx: "ApiContext", base: Optional[B] = None) -> Union[B, type["Bot"]]:
4951
from nonebot.adapters import Bot
5052

5153
_base = base or Bot

nonebug/mixin/call_api/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Api(Model):
1414
name: str
1515
data: dict[str, Any]
1616
result: Any
17-
exception: Exception | None
17+
exception: Optional[Exception]
1818
adapter: Optional["Adapter"]
1919

2020

@@ -24,5 +24,5 @@ class Send(Model):
2424
message: Union[str, "Message", "MessageSegment"]
2525
kwargs: dict[str, Any]
2626
result: Any
27-
exception: Exception | None
27+
exception: Optional[Exception]
2828
bot: Optional["Bot"]

nonebug/mixin/dependent.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from typing import TYPE_CHECKING, Any, Union
1+
from typing import TYPE_CHECKING, Any, Union, Callable, Optional
22
from contextlib import AsyncExitStack
3-
from collections.abc import Callable, Iterable
3+
from collections.abc import Iterable
44
from typing_extensions import final
55

66
import pytest
@@ -51,8 +51,8 @@ class DependentMixin(BaseApp):
5151
def test_dependent(
5252
self,
5353
dependent: Union["Dependent", Callable[..., Any]],
54-
allow_types: Iterable[type["Param"]] | None = None,
55-
parameterless: Iterable[Any] | None = None,
54+
allow_types: Optional[Iterable[type["Param"]]] = None,
55+
parameterless: Optional[Iterable[Any]] = None,
5656
) -> DependentContext:
5757
from nonebot.dependencies import Dependent
5858

nonebug/mixin/driver.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
from typing import Optional
12
from typing_extensions import final
23

34
from asgiref.typing import ASGIApplication
45
from async_asgi_testclient import TestClient
56

67
from nonebug.base import BaseApp, Context
78

8-
_global_client: TestClient | None = None
9+
_global_client: Optional[TestClient] = None
910

1011

1112
def set_global_client(client: TestClient):
@@ -17,7 +18,7 @@ def set_global_client(client: TestClient):
1718
_global_client = client
1819

1920

20-
def get_global_client() -> TestClient | None:
21+
def get_global_client() -> Optional[TestClient]:
2122
return _global_client
2223

2324

@@ -28,7 +29,7 @@ def __init__(
2829
app: BaseApp,
2930
*args,
3031
asgi: ASGIApplication,
31-
client: TestClient | None = None,
32+
client: Optional[TestClient] = None,
3233
**kwargs,
3334
):
3435
super().__init__(app, *args, **kwargs)
@@ -64,7 +65,7 @@ async def setup(self) -> None:
6465

6566

6667
class DriverMixin(BaseApp):
67-
def test_server(self, asgi: ASGIApplication | None = None) -> ServerContext:
68+
def test_server(self, asgi: Optional[ASGIApplication] = None) -> ServerContext:
6869
import nonebot
6970

7071
client = None

nonebug/mixin/process/__init__.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TYPE_CHECKING, Literal, TypedDict
1+
from typing import TYPE_CHECKING, Union, Literal, Optional, TypedDict
22
from contextlib import contextmanager
33
from collections import defaultdict
44
from contextvars import ContextVar
@@ -58,7 +58,7 @@ def __init__(
5858
self,
5959
app: "ProcessMixin",
6060
*args,
61-
matchers: dict[int, list[type["Matcher"]]] | None,
61+
matchers: Optional[dict[int, list[type["Matcher"]]]],
6262
**kwargs,
6363
):
6464
super().__init__(app, *args, **kwargs)
@@ -77,19 +77,21 @@ def receive_event(self, bot: "Bot", event: "Event") -> ReceiveEvent:
7777
self.event_list.append((receive_event, EventTest(checks=[], actions=[])))
7878
return receive_event
7979

80-
def should_pass_rule(self, matcher: type["Matcher"] | None = None) -> RulePass:
80+
def should_pass_rule(self, matcher: Optional[type["Matcher"]] = None) -> RulePass:
8181
rule = RulePass(matcher=matcher)
8282
self.currect_event_test["checks"].append(rule)
8383
return rule
8484

8585
def should_not_pass_rule(
86-
self, matcher: type["Matcher"] | None = None
86+
self, matcher: Optional[type["Matcher"]] = None
8787
) -> RuleNotPass:
8888
rule = RuleNotPass(matcher=matcher)
8989
self.currect_event_test["checks"].append(rule)
9090
return rule
9191

92-
def should_ignore_rule(self, matcher: type["Matcher"] | None = None) -> IgnoreRule:
92+
def should_ignore_rule(
93+
self, matcher: Optional[type["Matcher"]] = None
94+
) -> IgnoreRule:
9395
rule = IgnoreRule(matcher=matcher)
9496
self.currect_event_test["checks"].append(rule)
9597
return rule
@@ -123,21 +125,21 @@ def got_check_rule(self, matcher: type["Matcher"], result: bool) -> bool:
123125
return result
124126

125127
def should_pass_permission(
126-
self, matcher: type["Matcher"] | None = None
128+
self, matcher: Optional[type["Matcher"]] = None
127129
) -> PermissionPass:
128130
permission = PermissionPass(matcher=matcher)
129131
self.currect_event_test["checks"].append(permission)
130132
return permission
131133

132134
def should_not_pass_permission(
133-
self, matcher: type["Matcher"] | None = None
135+
self, matcher: Optional[type["Matcher"]] = None
134136
) -> PermissionNotPass:
135137
permission = PermissionNotPass(matcher=matcher)
136138
self.currect_event_test["checks"].append(permission)
137139
return permission
138140

139141
def should_ignore_permission(
140-
self, matcher: type["Matcher"] | None = None
142+
self, matcher: Optional[type["Matcher"]] = None
141143
) -> IgnorePermission:
142144
permission = IgnorePermission(matcher=matcher)
143145
self.currect_event_test["checks"].append(permission)
@@ -173,7 +175,7 @@ def got_check_permission(self, matcher: type["Matcher"], result: bool) -> bool:
173175
break
174176
return result
175177

176-
def should_paused(self, matcher: type["Matcher"] | None = None) -> Paused:
178+
def should_paused(self, matcher: Optional[type["Matcher"]] = None) -> Paused:
177179
if any(
178180
action.matcher is matcher for action in self.currect_event_test["actions"]
179181
):
@@ -182,7 +184,7 @@ def should_paused(self, matcher: type["Matcher"] | None = None) -> Paused:
182184
self.currect_event_test["actions"].append(paused)
183185
return paused
184186

185-
def should_rejected(self, matcher: type["Matcher"] | None = None) -> Rejected:
187+
def should_rejected(self, matcher: Optional[type["Matcher"]] = None) -> Rejected:
186188
if any(
187189
action.matcher is matcher for action in self.currect_event_test["actions"]
188190
):
@@ -191,7 +193,7 @@ def should_rejected(self, matcher: type["Matcher"] | None = None) -> Rejected:
191193
self.currect_event_test["actions"].append(rejected)
192194
return rejected
193195

194-
def should_finished(self, matcher: type["Matcher"] | None = None) -> Finished:
196+
def should_finished(self, matcher: Optional[type["Matcher"]] = None) -> Finished:
195197
if any(
196198
action.matcher is matcher for action in self.currect_event_test["actions"]
197199
):
@@ -285,13 +287,15 @@ async def run(self):
285287
class ProcessMixin(BaseApp):
286288
def test_matcher(
287289
self,
288-
m: None
289-
| type["Matcher"]
290-
| list[type["Matcher"]]
291-
| dict[int, list[type["Matcher"]]] = None,
290+
m: Union[
291+
None,
292+
type["Matcher"],
293+
list[type["Matcher"]],
294+
dict[int, list[type["Matcher"]]],
295+
] = None,
292296
/,
293297
) -> MatcherContext:
294-
matchers: dict[int, list[type["Matcher"]]] | None
298+
matchers: Optional[dict[int, list[type["Matcher"]]]]
295299
if m is None:
296300
matchers = None
297301
elif isinstance(m, list):

nonebug/mixin/process/fake.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from typing import TYPE_CHECKING
2-
from collections.abc import Callable, Awaitable
1+
from typing import TYPE_CHECKING, Callable
2+
from collections.abc import Awaitable
33
from typing_extensions import ParamSpec
44

55
from _pytest.outcomes import OutcomeException

0 commit comments

Comments
 (0)