mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-09-06 20:16:47 +00:00
🧑💻 Develop: 添加 ruff RUF 规则 (#2598)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
This commit is contained in:
@ -32,8 +32,8 @@ async def gen_async():
|
||||
|
||||
@dataclass
|
||||
class ClassDependency:
|
||||
x: int = Depends(gen_sync)
|
||||
y: int = Depends(gen_async)
|
||||
x: int = Depends(gen_sync) # noqa: RUF009
|
||||
y: int = Depends(gen_async) # noqa: RUF009
|
||||
|
||||
|
||||
class FooBot(Bot): ...
|
||||
|
@ -1,7 +1,7 @@
|
||||
from typing import List, Union, Optional
|
||||
|
||||
import pytest
|
||||
from pydantic import BaseModel
|
||||
from pydantic import Field, BaseModel
|
||||
|
||||
from nonebot.config import DOTENV_TYPE, BaseSettings, SettingsError
|
||||
|
||||
@ -18,7 +18,7 @@ class Example(BaseSettings):
|
||||
_env_nested_delimiter: Optional[str] = "__"
|
||||
|
||||
simple: str = ""
|
||||
complex: List[int] = [1]
|
||||
complex: List[int] = Field(default=[1])
|
||||
complex_none: Optional[List[int]] = None
|
||||
complex_union: Union[int, List[int]] = 1
|
||||
nested: Simple = Simple()
|
||||
|
@ -409,9 +409,9 @@ async def test_bot_connect_hook(app: App, driver: Driver):
|
||||
|
||||
disconn_should_be_called = True
|
||||
|
||||
if conn_hook not in {hook.call for hook in conn_hooks}:
|
||||
if conn_hook not in {hook.call for hook in conn_hooks}: # type: ignore
|
||||
pytest.fail("on_bot_connect hook not registered")
|
||||
if disconn_hook not in {hook.call for hook in disconn_hooks}:
|
||||
if disconn_hook not in {hook.call for hook in disconn_hooks}: # type: ignore
|
||||
pytest.fail("on_bot_disconnect hook not registered")
|
||||
|
||||
async with app.test_api() as ctx:
|
||||
|
@ -244,7 +244,7 @@ async def test_default_permission_updater(app: App):
|
||||
matcher = test_permission_updater()
|
||||
new_perm = await matcher.update_permission(bot, event)
|
||||
assert len(new_perm.checkers) == 1
|
||||
checker = list(new_perm.checkers)[0].call
|
||||
checker = next(iter(new_perm.checkers)).call
|
||||
assert isinstance(checker, User)
|
||||
assert checker.users == ("test",)
|
||||
assert checker.perm is default_permission
|
||||
@ -258,7 +258,7 @@ async def test_user_permission_updater(app: App):
|
||||
)
|
||||
|
||||
event = make_fake_event(_session_id="test")()
|
||||
user_permission = list(test_user_permission_updater.permission.checkers)[0].call
|
||||
user_permission = next(iter(test_user_permission_updater.permission.checkers)).call
|
||||
assert isinstance(user_permission, User)
|
||||
assert user_permission.perm is default_permission
|
||||
async with app.test_api() as ctx:
|
||||
@ -266,7 +266,7 @@ async def test_user_permission_updater(app: App):
|
||||
matcher = test_user_permission_updater()
|
||||
new_perm = await matcher.update_permission(bot, event)
|
||||
assert len(new_perm.checkers) == 1
|
||||
checker = list(new_perm.checkers)[0].call
|
||||
checker = next(iter(new_perm.checkers)).call
|
||||
assert isinstance(checker, User)
|
||||
assert checker.users == ("test",)
|
||||
assert checker.perm is default_permission
|
||||
|
@ -212,7 +212,7 @@ async def test_event(app: App):
|
||||
ctx.pass_params(event=fake_fooevent)
|
||||
ctx.should_return(fake_fooevent)
|
||||
|
||||
with pytest.raises(TypeMisMatch): # noqa: PT012
|
||||
with pytest.raises(TypeMisMatch):
|
||||
async with app.test_dependent(sub_event, allow_types=[EventParam]) as ctx:
|
||||
ctx.pass_params(event=fake_event)
|
||||
|
||||
@ -436,7 +436,7 @@ async def test_matcher(app: App):
|
||||
ctx.pass_params(matcher=foo_matcher)
|
||||
ctx.should_return(foo_matcher)
|
||||
|
||||
with pytest.raises(TypeMisMatch): # noqa: PT012
|
||||
with pytest.raises(TypeMisMatch):
|
||||
async with app.test_dependent(sub_matcher, allow_types=[MatcherParam]) as ctx:
|
||||
ctx.pass_params(matcher=fake_matcher)
|
||||
|
||||
|
@ -57,7 +57,7 @@ async def test_permission(app: App):
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(("type", "expected"), [("message", True), ("notice", False)])
|
||||
async def test_message(type: str, expected: bool):
|
||||
dependent = list(MESSAGE.checkers)[0]
|
||||
dependent = next(iter(MESSAGE.checkers))
|
||||
checker = dependent.call
|
||||
|
||||
assert isinstance(checker, Message)
|
||||
@ -69,7 +69,7 @@ async def test_message(type: str, expected: bool):
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(("type", "expected"), [("message", False), ("notice", True)])
|
||||
async def test_notice(type: str, expected: bool):
|
||||
dependent = list(NOTICE.checkers)[0]
|
||||
dependent = next(iter(NOTICE.checkers))
|
||||
checker = dependent.call
|
||||
|
||||
assert isinstance(checker, Notice)
|
||||
@ -81,7 +81,7 @@ async def test_notice(type: str, expected: bool):
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(("type", "expected"), [("message", False), ("request", True)])
|
||||
async def test_request(type: str, expected: bool):
|
||||
dependent = list(REQUEST.checkers)[0]
|
||||
dependent = next(iter(REQUEST.checkers))
|
||||
checker = dependent.call
|
||||
|
||||
assert isinstance(checker, Request)
|
||||
@ -95,7 +95,7 @@ async def test_request(type: str, expected: bool):
|
||||
("type", "expected"), [("message", False), ("meta_event", True)]
|
||||
)
|
||||
async def test_metaevent(type: str, expected: bool):
|
||||
dependent = list(METAEVENT.checkers)[0]
|
||||
dependent = next(iter(METAEVENT.checkers))
|
||||
checker = dependent.call
|
||||
|
||||
assert isinstance(checker, MetaEvent)
|
||||
@ -116,7 +116,7 @@ async def test_metaevent(type: str, expected: bool):
|
||||
],
|
||||
)
|
||||
async def test_superuser(app: App, type: str, user_id: str, expected: bool):
|
||||
dependent = list(SUPERUSER.checkers)[0]
|
||||
dependent = next(iter(SUPERUSER.checkers))
|
||||
checker = dependent.call
|
||||
|
||||
assert isinstance(checker, SuperUser)
|
||||
@ -140,7 +140,7 @@ async def test_superuser(app: App, type: str, user_id: str, expected: bool):
|
||||
async def test_user(
|
||||
app: App, session_ids: Tuple[str, ...], session_id: Optional[str], expected: bool
|
||||
):
|
||||
dependent = list(USER(*session_ids).checkers)[0]
|
||||
dependent = next(iter(USER(*session_ids).checkers))
|
||||
checker = dependent.call
|
||||
|
||||
assert isinstance(checker, User)
|
||||
|
@ -170,7 +170,7 @@ async def test_startswith(
|
||||
expected: bool,
|
||||
):
|
||||
test_startswith = startswith(msg, ignorecase)
|
||||
dependent = list(test_startswith.checkers)[0]
|
||||
dependent = next(iter(test_startswith.checkers))
|
||||
checker = dependent.call
|
||||
|
||||
msg = (msg,) if isinstance(msg, str) else msg
|
||||
@ -210,7 +210,7 @@ async def test_endswith(
|
||||
expected: bool,
|
||||
):
|
||||
test_endswith = endswith(msg, ignorecase)
|
||||
dependent = list(test_endswith.checkers)[0]
|
||||
dependent = next(iter(test_endswith.checkers))
|
||||
checker = dependent.call
|
||||
|
||||
msg = (msg,) if isinstance(msg, str) else msg
|
||||
@ -250,7 +250,7 @@ async def test_fullmatch(
|
||||
expected: bool,
|
||||
):
|
||||
test_fullmatch = fullmatch(msg, ignorecase)
|
||||
dependent = list(test_fullmatch.checkers)[0]
|
||||
dependent = next(iter(test_fullmatch.checkers))
|
||||
checker = dependent.call
|
||||
|
||||
msg = (msg,) if isinstance(msg, str) else msg
|
||||
@ -285,7 +285,7 @@ async def test_keyword(
|
||||
expected: bool,
|
||||
):
|
||||
test_keyword = keyword(*kws)
|
||||
dependent = list(test_keyword.checkers)[0]
|
||||
dependent = next(iter(test_keyword.checkers))
|
||||
checker = dependent.call
|
||||
|
||||
assert isinstance(checker, KeywordsRule)
|
||||
@ -331,7 +331,7 @@ async def test_command(
|
||||
expected: bool,
|
||||
):
|
||||
test_command = command(*cmds, force_whitespace=force_whitespace)
|
||||
dependent = list(test_command.checkers)[0]
|
||||
dependent = next(iter(test_command.checkers))
|
||||
checker = dependent.call
|
||||
|
||||
assert isinstance(checker, CommandRule)
|
||||
@ -352,7 +352,7 @@ async def test_shell_command():
|
||||
MessageSegment = Message.get_segment_class()
|
||||
|
||||
test_not_cmd = shell_command(CMD)
|
||||
dependent = list(test_not_cmd.checkers)[0]
|
||||
dependent = next(iter(test_not_cmd.checkers))
|
||||
checker = dependent.call
|
||||
assert isinstance(checker, ShellCommandRule)
|
||||
message = Message()
|
||||
@ -361,7 +361,7 @@ async def test_shell_command():
|
||||
assert not await dependent(event=event, state=state)
|
||||
|
||||
test_no_parser = shell_command(CMD)
|
||||
dependent = list(test_no_parser.checkers)[0]
|
||||
dependent = next(iter(test_no_parser.checkers))
|
||||
checker = dependent.call
|
||||
assert isinstance(checker, ShellCommandRule)
|
||||
message = Message()
|
||||
@ -375,7 +375,7 @@ async def test_shell_command():
|
||||
parser.add_argument("-a", required=True)
|
||||
|
||||
test_simple_parser = shell_command(CMD, parser=parser)
|
||||
dependent = list(test_simple_parser.checkers)[0]
|
||||
dependent = next(iter(test_simple_parser.checkers))
|
||||
checker = dependent.call
|
||||
assert isinstance(checker, ShellCommandRule)
|
||||
message = Message("-a 1")
|
||||
@ -386,7 +386,7 @@ async def test_shell_command():
|
||||
assert state[SHELL_ARGS] == Namespace(a="1")
|
||||
|
||||
test_parser_help = shell_command(CMD, parser=parser)
|
||||
dependent = list(test_parser_help.checkers)[0]
|
||||
dependent = next(iter(test_parser_help.checkers))
|
||||
checker = dependent.call
|
||||
assert isinstance(checker, ShellCommandRule)
|
||||
message = Message("-h")
|
||||
@ -399,7 +399,7 @@ async def test_shell_command():
|
||||
assert state[SHELL_ARGS].message == parser.format_help()
|
||||
|
||||
test_parser_error = shell_command(CMD, parser=parser)
|
||||
dependent = list(test_parser_error.checkers)[0]
|
||||
dependent = next(iter(test_parser_error.checkers))
|
||||
checker = dependent.call
|
||||
assert isinstance(checker, ShellCommandRule)
|
||||
message = Message()
|
||||
@ -412,7 +412,7 @@ async def test_shell_command():
|
||||
assert state[SHELL_ARGS].message.startswith(parser.format_usage() + "test: error:")
|
||||
|
||||
test_parser_remain_args = shell_command(CMD, parser=parser)
|
||||
dependent = list(test_parser_remain_args.checkers)[0]
|
||||
dependent = next(iter(test_parser_remain_args.checkers))
|
||||
checker = dependent.call
|
||||
assert isinstance(checker, ShellCommandRule)
|
||||
message = MessageSegment.text("-a 1 2") + MessageSegment.image("test")
|
||||
@ -425,7 +425,7 @@ async def test_shell_command():
|
||||
assert state[SHELL_ARGS].message.startswith(parser.format_usage() + "test: error:")
|
||||
|
||||
test_message_parser = shell_command(CMD, parser=parser)
|
||||
dependent = list(test_message_parser.checkers)[0]
|
||||
dependent = next(iter(test_message_parser.checkers))
|
||||
checker = dependent.call
|
||||
assert isinstance(checker, ShellCommandRule)
|
||||
message = MessageSegment.text("-a") + MessageSegment.image("test")
|
||||
@ -440,7 +440,7 @@ async def test_shell_command():
|
||||
parser.add_argument("-a", required=True)
|
||||
|
||||
test_not_exit = shell_command(CMD, parser=parser)
|
||||
dependent = list(test_not_exit.checkers)[0]
|
||||
dependent = next(iter(test_not_exit.checkers))
|
||||
checker = dependent.call
|
||||
assert isinstance(checker, ShellCommandRule)
|
||||
message = Message()
|
||||
@ -476,7 +476,7 @@ async def test_regex(
|
||||
matched: Optional[Match[str]],
|
||||
):
|
||||
test_regex = regex(pattern)
|
||||
dependent = list(test_regex.checkers)[0]
|
||||
dependent = next(iter(test_regex.checkers))
|
||||
checker = dependent.call
|
||||
|
||||
assert isinstance(checker, RegexRule)
|
||||
@ -499,7 +499,7 @@ async def test_regex(
|
||||
@pytest.mark.parametrize("expected", [True, False])
|
||||
async def test_to_me(expected: bool):
|
||||
test_to_me = to_me()
|
||||
dependent = list(test_to_me.checkers)[0]
|
||||
dependent = next(iter(test_to_me.checkers))
|
||||
checker = dependent.call
|
||||
|
||||
assert isinstance(checker, ToMeRule)
|
||||
@ -515,7 +515,7 @@ async def test_is_type():
|
||||
Event3 = make_fake_event()
|
||||
|
||||
test_type = is_type(Event1, Event2)
|
||||
dependent = list(test_type.checkers)[0]
|
||||
dependent = next(iter(test_type.checkers))
|
||||
checker = dependent.call
|
||||
|
||||
assert isinstance(checker, IsTypeRule)
|
||||
|
Reference in New Issue
Block a user