mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-09-06 20:16:47 +00:00
🚨 Develop: 完全使用 ruff 替代 isort 与 black (#3151)
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
from .adapter import Adapter as Adapter
|
||||
from .bot import Bot as Bot
|
||||
from .event import Event as Event
|
||||
from .adapter import Adapter as Adapter
|
||||
from .message import Message as Message
|
||||
from .message import MessageSegment as MessageSegment
|
||||
from .template import MessageTemplate as MessageTemplate
|
||||
|
@ -1,21 +1,21 @@
|
||||
import abc
|
||||
from typing import Any
|
||||
from collections.abc import AsyncGenerator
|
||||
from contextlib import asynccontextmanager
|
||||
from typing import Any
|
||||
|
||||
from nonebot.config import Config
|
||||
from nonebot.internal.driver._lifespan import LIFESPAN_FUNC
|
||||
from nonebot.internal.driver import (
|
||||
Driver,
|
||||
Request,
|
||||
Response,
|
||||
ASGIMixin,
|
||||
WebSocket,
|
||||
Driver,
|
||||
HTTPClientMixin,
|
||||
HTTPServerSetup,
|
||||
Request,
|
||||
Response,
|
||||
WebSocket,
|
||||
WebSocketClientMixin,
|
||||
WebSocketServerSetup,
|
||||
)
|
||||
from nonebot.internal.driver._lifespan import LIFESPAN_FUNC
|
||||
|
||||
from .bot import Bot
|
||||
|
||||
|
@ -1,19 +1,19 @@
|
||||
import abc
|
||||
from functools import partial
|
||||
from typing import TYPE_CHECKING, Any, Union, ClassVar, Optional, Protocol
|
||||
from typing import TYPE_CHECKING, Any, ClassVar, Optional, Protocol, Union
|
||||
|
||||
import anyio
|
||||
from exceptiongroup import BaseExceptionGroup, catch
|
||||
|
||||
from nonebot.log import logger
|
||||
from nonebot.config import Config
|
||||
from nonebot.exception import MockApiException
|
||||
from nonebot.utils import flatten_exception_group
|
||||
from nonebot.log import logger
|
||||
from nonebot.typing import T_CalledAPIHook, T_CallingAPIHook
|
||||
from nonebot.utils import flatten_exception_group
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .event import Event
|
||||
from .adapter import Adapter
|
||||
from .event import Event
|
||||
from .message import Message, MessageSegment
|
||||
|
||||
class _ApiCall(Protocol):
|
||||
|
@ -3,8 +3,8 @@ from typing import Any, TypeVar
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from nonebot.utils import DataclassEncoder
|
||||
from nonebot.compat import PYDANTIC_V2, ConfigDict
|
||||
from nonebot.utils import DataclassEncoder
|
||||
|
||||
from .message import Message
|
||||
|
||||
|
@ -1,18 +1,18 @@
|
||||
import abc
|
||||
from copy import deepcopy
|
||||
from typing_extensions import Self
|
||||
from collections.abc import Iterable
|
||||
from dataclasses import field, asdict, dataclass
|
||||
from copy import deepcopy
|
||||
from dataclasses import asdict, dataclass, field
|
||||
from typing import ( # noqa: UP035
|
||||
Any,
|
||||
Type,
|
||||
Union,
|
||||
Generic,
|
||||
TypeVar,
|
||||
Optional,
|
||||
SupportsIndex,
|
||||
Type,
|
||||
TypeVar,
|
||||
Union,
|
||||
overload,
|
||||
)
|
||||
from typing_extensions import Self
|
||||
|
||||
from nonebot.compat import custom_validation, type_validate_python
|
||||
|
||||
@ -329,8 +329,9 @@ class Message(list[TMS], abc.ABC):
|
||||
return self[type_]
|
||||
|
||||
iterator, filtered = (
|
||||
seg for seg in self if seg.type == type_
|
||||
), self.__class__()
|
||||
(seg for seg in self if seg.type == type_),
|
||||
self.__class__(),
|
||||
)
|
||||
for _ in range(count):
|
||||
seg = next(iterator, None)
|
||||
if seg is None:
|
||||
|
@ -1,20 +1,19 @@
|
||||
from _string import formatter_field_name_split # type: ignore
|
||||
from collections.abc import Mapping, Sequence
|
||||
import functools
|
||||
from string import Formatter
|
||||
from typing_extensions import TypeAlias
|
||||
from collections.abc import Mapping, Sequence
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
Any,
|
||||
Union,
|
||||
Generic,
|
||||
TypeVar,
|
||||
Callable,
|
||||
Generic,
|
||||
Optional,
|
||||
TypeVar,
|
||||
Union,
|
||||
cast,
|
||||
overload,
|
||||
)
|
||||
|
||||
from _string import formatter_field_name_split # type: ignore
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .message import Message, MessageSegment
|
||||
|
@ -1,31 +1,31 @@
|
||||
from .model import URL as URL
|
||||
from .model import RawURL as RawURL
|
||||
from .abstract import Mixin as Mixin
|
||||
from .model import Cookies as Cookies
|
||||
from .model import Request as Request
|
||||
from .abstract import Driver as Driver
|
||||
from .model import FileType as FileType
|
||||
from .model import Response as Response
|
||||
from .model import DataTypes as DataTypes
|
||||
from .model import FileTypes as FileTypes
|
||||
from .model import WebSocket as WebSocket
|
||||
from .model import FilesTypes as FilesTypes
|
||||
from .model import QueryTypes as QueryTypes
|
||||
from .abstract import ASGIMixin as ASGIMixin
|
||||
from .model import CookieTypes as CookieTypes
|
||||
from .model import FileContent as FileContent
|
||||
from .model import HTTPVersion as HTTPVersion
|
||||
from .model import HeaderTypes as HeaderTypes
|
||||
from .model import SimpleQuery as SimpleQuery
|
||||
from .model import ContentTypes as ContentTypes
|
||||
from .model import QueryVariable as QueryVariable
|
||||
from .abstract import ForwardMixin as ForwardMixin
|
||||
from .abstract import ReverseMixin as ReverseMixin
|
||||
from .abstract import Driver as Driver
|
||||
from .abstract import ForwardDriver as ForwardDriver
|
||||
from .abstract import ReverseDriver as ReverseDriver
|
||||
from .combine import combine_driver as combine_driver
|
||||
from .model import HTTPServerSetup as HTTPServerSetup
|
||||
from .abstract import ForwardMixin as ForwardMixin
|
||||
from .abstract import HTTPClientMixin as HTTPClientMixin
|
||||
from .abstract import HTTPClientSession as HTTPClientSession
|
||||
from .model import WebSocketServerSetup as WebSocketServerSetup
|
||||
from .abstract import Mixin as Mixin
|
||||
from .abstract import ReverseDriver as ReverseDriver
|
||||
from .abstract import ReverseMixin as ReverseMixin
|
||||
from .abstract import WebSocketClientMixin as WebSocketClientMixin
|
||||
from .combine import combine_driver as combine_driver
|
||||
from .model import URL as URL
|
||||
from .model import ContentTypes as ContentTypes
|
||||
from .model import Cookies as Cookies
|
||||
from .model import CookieTypes as CookieTypes
|
||||
from .model import DataTypes as DataTypes
|
||||
from .model import FileContent as FileContent
|
||||
from .model import FilesTypes as FilesTypes
|
||||
from .model import FileType as FileType
|
||||
from .model import FileTypes as FileTypes
|
||||
from .model import HeaderTypes as HeaderTypes
|
||||
from .model import HTTPServerSetup as HTTPServerSetup
|
||||
from .model import HTTPVersion as HTTPVersion
|
||||
from .model import QueryTypes as QueryTypes
|
||||
from .model import QueryVariable as QueryVariable
|
||||
from .model import RawURL as RawURL
|
||||
from .model import Request as Request
|
||||
from .model import Response as Response
|
||||
from .model import SimpleQuery as SimpleQuery
|
||||
from .model import WebSocket as WebSocket
|
||||
from .model import WebSocketServerSetup as WebSocketServerSetup
|
||||
|
@ -1,13 +1,13 @@
|
||||
from collections.abc import Awaitable, Iterable
|
||||
from types import TracebackType
|
||||
from typing import Any, Callable, Optional, Union, cast
|
||||
from typing_extensions import TypeAlias
|
||||
from collections.abc import Iterable, Awaitable
|
||||
from typing import Any, Union, Callable, Optional, cast
|
||||
|
||||
import anyio
|
||||
from anyio.abc import TaskGroup
|
||||
from exceptiongroup import suppress
|
||||
|
||||
from nonebot.utils import run_sync, is_coroutine_callable
|
||||
from nonebot.utils import is_coroutine_callable, run_sync
|
||||
|
||||
SYNC_LIFESPAN_FUNC: TypeAlias = Callable[[], Any]
|
||||
ASYNC_LIFESPAN_FUNC: TypeAlias = Callable[[], Awaitable[Any]]
|
||||
|
@ -1,41 +1,41 @@
|
||||
import abc
|
||||
from types import TracebackType
|
||||
from collections.abc import AsyncGenerator
|
||||
from typing_extensions import Self, TypeAlias
|
||||
from contextlib import AsyncExitStack, asynccontextmanager
|
||||
from typing import TYPE_CHECKING, Any, Union, ClassVar, Optional
|
||||
from types import TracebackType
|
||||
from typing import TYPE_CHECKING, Any, ClassVar, Optional, Union
|
||||
from typing_extensions import Self, TypeAlias
|
||||
|
||||
from anyio.abc import TaskGroup
|
||||
from anyio import CancelScope, create_task_group
|
||||
from anyio.abc import TaskGroup
|
||||
from exceptiongroup import BaseExceptionGroup, catch
|
||||
|
||||
from nonebot.log import logger
|
||||
from nonebot.config import Env, Config
|
||||
from nonebot.config import Config, Env
|
||||
from nonebot.dependencies import Dependent
|
||||
from nonebot.exception import SkippedException
|
||||
from nonebot.internal.params import BotParam, DependParam, DefaultParam
|
||||
from nonebot.utils import escape_tag, run_coro_with_catch, flatten_exception_group
|
||||
from nonebot.internal.params import BotParam, DefaultParam, DependParam
|
||||
from nonebot.log import logger
|
||||
from nonebot.typing import (
|
||||
T_DependencyCache,
|
||||
T_BotConnectionHook,
|
||||
T_BotDisconnectionHook,
|
||||
T_DependencyCache,
|
||||
)
|
||||
from nonebot.utils import escape_tag, flatten_exception_group, run_coro_with_catch
|
||||
|
||||
from ._lifespan import LIFESPAN_FUNC, Lifespan
|
||||
from .model import (
|
||||
CookieTypes,
|
||||
HeaderTypes,
|
||||
HTTPServerSetup,
|
||||
HTTPVersion,
|
||||
QueryTypes,
|
||||
Request,
|
||||
Response,
|
||||
WebSocket,
|
||||
QueryTypes,
|
||||
CookieTypes,
|
||||
HeaderTypes,
|
||||
HTTPVersion,
|
||||
HTTPServerSetup,
|
||||
WebSocketServerSetup,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from nonebot.internal.adapter import Bot, Adapter
|
||||
from nonebot.internal.adapter import Adapter, Bot
|
||||
|
||||
|
||||
BOT_HOOK_PARAMS = [DependParam, BotParam, DefaultParam]
|
||||
|
@ -1,6 +1,6 @@
|
||||
from typing import TYPE_CHECKING, Union, TypeVar, overload
|
||||
from typing import TYPE_CHECKING, TypeVar, Union, overload
|
||||
|
||||
from .abstract import Mixin, Driver
|
||||
from .abstract import Driver, Mixin
|
||||
|
||||
D = TypeVar("D", bound="Driver")
|
||||
|
||||
@ -39,6 +39,4 @@ def combine_driver(
|
||||
+ "+".join(x.type.__get__(self) for x in mixins) # type: ignore
|
||||
)
|
||||
|
||||
return type(
|
||||
"CombinedDriver", (*mixins, driver), {"type": property(type_)}
|
||||
) # type: ignore
|
||||
return type("CombinedDriver", (*mixins, driver), {"type": property(type_)}) # type: ignore
|
||||
|
@ -1,14 +1,14 @@
|
||||
import abc
|
||||
import urllib.request
|
||||
from enum import Enum
|
||||
from collections.abc import Awaitable, Iterator, Mapping, MutableMapping
|
||||
from dataclasses import dataclass
|
||||
from typing_extensions import TypeAlias
|
||||
from enum import Enum
|
||||
from http.cookiejar import Cookie, CookieJar
|
||||
from typing import IO, Any, Union, Callable, Optional
|
||||
from collections.abc import Mapping, Iterator, Awaitable, MutableMapping
|
||||
from typing import IO, Any, Callable, Optional, Union
|
||||
from typing_extensions import TypeAlias
|
||||
import urllib.request
|
||||
|
||||
from yarl import URL as URL
|
||||
from multidict import CIMultiDict
|
||||
from yarl import URL as URL
|
||||
|
||||
RawURL: TypeAlias = tuple[bytes, bytes, Optional[int], bytes]
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
from .manager import MatcherManager as MatcherManager
|
||||
from .provider import MatcherProvider as MatcherProvider
|
||||
from .provider import DEFAULT_PROVIDER_CLASS as DEFAULT_PROVIDER_CLASS
|
||||
from .provider import MatcherProvider as MatcherProvider
|
||||
|
||||
matchers = MatcherManager()
|
||||
|
||||
from .matcher import Matcher as Matcher
|
||||
from .matcher import current_bot as current_bot
|
||||
from .matcher import MatcherSource as MatcherSource
|
||||
from .matcher import current_bot as current_bot
|
||||
from .matcher import current_event as current_event
|
||||
from .matcher import current_handler as current_handler
|
||||
from .matcher import current_matcher as current_matcher
|
||||
|
@ -1,5 +1,5 @@
|
||||
from typing import TYPE_CHECKING, Union, TypeVar, Optional, overload
|
||||
from collections.abc import Iterator, KeysView, ItemsView, ValuesView, MutableMapping
|
||||
from collections.abc import ItemsView, Iterator, KeysView, MutableMapping, ValuesView
|
||||
from typing import TYPE_CHECKING, Optional, TypeVar, Union, overload
|
||||
|
||||
from .provider import DEFAULT_PROVIDER_CLASS, MatcherProvider
|
||||
|
||||
@ -74,9 +74,9 @@ class MatcherManager(MutableMapping[int, list[type["Matcher"]]]):
|
||||
self.provider.clear()
|
||||
|
||||
def update( # pyright: ignore[reportIncompatibleMethodOverride]
|
||||
self, __m: MutableMapping[int, list[type["Matcher"]]]
|
||||
self, m: MutableMapping[int, list[type["Matcher"]]], /
|
||||
) -> None:
|
||||
self.provider.update(__m)
|
||||
self.provider.update(m)
|
||||
|
||||
def setdefault(
|
||||
self, key: int, default: list[type["Matcher"]]
|
||||
|
@ -1,34 +1,44 @@
|
||||
import sys
|
||||
import inspect
|
||||
import warnings
|
||||
from pathlib import Path
|
||||
from types import ModuleType
|
||||
from dataclasses import dataclass
|
||||
from contextvars import ContextVar
|
||||
from typing_extensions import Self
|
||||
from collections.abc import Iterable
|
||||
from datetime import datetime, timedelta
|
||||
from contextlib import AsyncExitStack, contextmanager
|
||||
from contextvars import ContextVar
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime, timedelta
|
||||
import inspect
|
||||
from pathlib import Path
|
||||
import sys
|
||||
from types import ModuleType
|
||||
from typing import ( # noqa: UP035
|
||||
TYPE_CHECKING,
|
||||
Any,
|
||||
Type,
|
||||
Union,
|
||||
TypeVar,
|
||||
Callable,
|
||||
ClassVar,
|
||||
NoReturn,
|
||||
Optional,
|
||||
Type,
|
||||
TypeVar,
|
||||
Union,
|
||||
overload,
|
||||
)
|
||||
from typing_extensions import Self
|
||||
import warnings
|
||||
|
||||
from exceptiongroup import BaseExceptionGroup, catch
|
||||
|
||||
from nonebot.log import logger
|
||||
from nonebot.internal.rule import Rule
|
||||
from nonebot.dependencies import Param, Dependent
|
||||
from nonebot.internal.permission import User, Permission
|
||||
from nonebot.utils import classproperty, flatten_exception_group
|
||||
from nonebot.consts import (
|
||||
ARG_KEY,
|
||||
LAST_RECEIVE_KEY,
|
||||
RECEIVE_KEY,
|
||||
REJECT_CACHE_TARGET,
|
||||
REJECT_TARGET,
|
||||
)
|
||||
from nonebot.dependencies import Dependent, Param
|
||||
from nonebot.exception import (
|
||||
FinishedException,
|
||||
PausedException,
|
||||
RejectedException,
|
||||
SkippedException,
|
||||
StopPropagation,
|
||||
)
|
||||
from nonebot.internal.adapter import (
|
||||
Bot,
|
||||
Event,
|
||||
@ -36,37 +46,27 @@ from nonebot.internal.adapter import (
|
||||
MessageSegment,
|
||||
MessageTemplate,
|
||||
)
|
||||
from nonebot.typing import (
|
||||
T_State,
|
||||
T_Handler,
|
||||
T_TypeUpdater,
|
||||
T_DependencyCache,
|
||||
T_PermissionUpdater,
|
||||
)
|
||||
from nonebot.consts import (
|
||||
ARG_KEY,
|
||||
RECEIVE_KEY,
|
||||
REJECT_TARGET,
|
||||
LAST_RECEIVE_KEY,
|
||||
REJECT_CACHE_TARGET,
|
||||
)
|
||||
from nonebot.exception import (
|
||||
PausedException,
|
||||
StopPropagation,
|
||||
SkippedException,
|
||||
FinishedException,
|
||||
RejectedException,
|
||||
)
|
||||
from nonebot.internal.params import (
|
||||
Depends,
|
||||
ArgParam,
|
||||
BotParam,
|
||||
EventParam,
|
||||
StateParam,
|
||||
DependParam,
|
||||
DefaultParam,
|
||||
DependParam,
|
||||
Depends,
|
||||
EventParam,
|
||||
MatcherParam,
|
||||
StateParam,
|
||||
)
|
||||
from nonebot.internal.permission import Permission, User
|
||||
from nonebot.internal.rule import Rule
|
||||
from nonebot.log import logger
|
||||
from nonebot.typing import (
|
||||
T_DependencyCache,
|
||||
T_Handler,
|
||||
T_PermissionUpdater,
|
||||
T_State,
|
||||
T_TypeUpdater,
|
||||
)
|
||||
from nonebot.utils import classproperty, flatten_exception_group
|
||||
|
||||
from . import matchers
|
||||
|
||||
@ -861,7 +861,7 @@ class Matcher(metaclass=MatcherMeta):
|
||||
def _handle_special_exception(
|
||||
exc_group: BaseExceptionGroup[
|
||||
Union[FinishedException, RejectedException, PausedException]
|
||||
]
|
||||
],
|
||||
):
|
||||
nonlocal exc
|
||||
excs = list(flatten_exception_group(exc_group))
|
||||
|
@ -1,7 +1,7 @@
|
||||
import abc
|
||||
from typing import TYPE_CHECKING
|
||||
from collections import defaultdict
|
||||
from collections.abc import Mapping, MutableMapping
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .matcher import Matcher
|
||||
|
@ -1,46 +1,46 @@
|
||||
import inspect
|
||||
from contextlib import AsyncExitStack, asynccontextmanager, contextmanager
|
||||
from enum import Enum
|
||||
from typing_extensions import Self, get_args, override, get_origin
|
||||
from contextlib import AsyncExitStack, contextmanager, asynccontextmanager
|
||||
import inspect
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
Any,
|
||||
Union,
|
||||
Literal,
|
||||
Callable,
|
||||
Optional,
|
||||
Annotated,
|
||||
Any,
|
||||
Callable,
|
||||
Literal,
|
||||
Optional,
|
||||
Union,
|
||||
cast,
|
||||
)
|
||||
from typing_extensions import Self, get_args, get_origin, override
|
||||
|
||||
import anyio
|
||||
from exceptiongroup import BaseExceptionGroup, catch
|
||||
from pydantic.fields import FieldInfo as PydanticFieldInfo
|
||||
|
||||
from nonebot.exception import SkippedException
|
||||
from nonebot.dependencies import Param, Dependent
|
||||
from nonebot.dependencies.utils import check_field_type
|
||||
from nonebot.compat import FieldInfo, ModelField, PydanticUndefined, extract_field_info
|
||||
from nonebot.dependencies import Dependent, Param
|
||||
from nonebot.dependencies.utils import check_field_type
|
||||
from nonebot.exception import SkippedException
|
||||
from nonebot.typing import (
|
||||
_STATE_FLAG,
|
||||
T_State,
|
||||
T_Handler,
|
||||
T_DependencyCache,
|
||||
T_Handler,
|
||||
T_State,
|
||||
origin_is_annotated,
|
||||
)
|
||||
from nonebot.utils import (
|
||||
generic_check_issubclass,
|
||||
get_name,
|
||||
run_sync,
|
||||
is_gen_callable,
|
||||
run_sync_ctx_manager,
|
||||
is_async_gen_callable,
|
||||
is_coroutine_callable,
|
||||
generic_check_issubclass,
|
||||
is_gen_callable,
|
||||
run_sync,
|
||||
run_sync_ctx_manager,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.adapters import Bot, Event
|
||||
from nonebot.matcher import Matcher
|
||||
|
||||
|
||||
class DependsInner:
|
||||
|
@ -1,16 +1,16 @@
|
||||
from typing_extensions import Self
|
||||
from contextlib import AsyncExitStack
|
||||
from typing import Union, ClassVar, NoReturn, Optional
|
||||
from typing import ClassVar, NoReturn, Optional, Union
|
||||
from typing_extensions import Self
|
||||
|
||||
import anyio
|
||||
|
||||
from nonebot.dependencies import Dependent
|
||||
from nonebot.utils import run_coro_with_catch
|
||||
from nonebot.exception import SkippedException
|
||||
from nonebot.typing import T_DependencyCache, T_PermissionChecker
|
||||
from nonebot.utils import run_coro_with_catch
|
||||
|
||||
from .adapter import Bot, Event
|
||||
from .params import Param, BotParam, EventParam, DependParam, DefaultParam
|
||||
from .params import BotParam, DefaultParam, DependParam, EventParam, Param
|
||||
|
||||
|
||||
class Permission:
|
||||
@ -124,7 +124,7 @@ class User:
|
||||
perm: 需同时满足的权限
|
||||
"""
|
||||
|
||||
__slots__ = ("users", "perm")
|
||||
__slots__ = ("perm", "users")
|
||||
|
||||
def __init__(
|
||||
self, users: tuple[str, ...], perm: Optional[Permission] = None
|
||||
|
@ -1,15 +1,15 @@
|
||||
from contextlib import AsyncExitStack
|
||||
from typing import Union, ClassVar, NoReturn, Optional
|
||||
from typing import ClassVar, NoReturn, Optional, Union
|
||||
|
||||
import anyio
|
||||
from exceptiongroup import BaseExceptionGroup, catch
|
||||
|
||||
from nonebot.dependencies import Dependent
|
||||
from nonebot.exception import SkippedException
|
||||
from nonebot.typing import T_State, T_RuleChecker, T_DependencyCache
|
||||
from nonebot.typing import T_DependencyCache, T_RuleChecker, T_State
|
||||
|
||||
from .adapter import Bot, Event
|
||||
from .params import Param, BotParam, EventParam, StateParam, DependParam, DefaultParam
|
||||
from .params import BotParam, DefaultParam, DependParam, EventParam, Param, StateParam
|
||||
|
||||
|
||||
class Rule:
|
||||
|
Reference in New Issue
Block a user