Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13"]
python-version: ["3.11", "3.12", "3.13"]
os: [ubuntu-latest, windows-latest, macos-latest]
env: [pydantic-v1, pydantic-v2]
env:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ _✨ 跨平台 Python 异步机器人框架 ✨_
<a href="https://pypi.python.org/pypi/nonebot2">
<img src="https://img.shields.io/pypi/v/nonebot2?logo=python&logoColor=edb641" alt="pypi">
</a>
<img src="https://img.shields.io/badge/python-3.10+-blue?logo=python&logoColor=edb641" alt="python">
<img src="https://img.shields.io/badge/python-3.11+-blue?logo=python&logoColor=edb641" alt="python">
<a href="https://github.com/psf/black">
<img src="https://img.shields.io/badge/code%20style-black-000000.svg?logo=python&logoColor=edb641" alt="black">
</a>
Expand Down
3 changes: 2 additions & 1 deletion nonebot/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
Generic,
Literal,
Protocol,
Self,
TypeAlias,
TypeVar,
cast,
get_args,
get_origin,
overload,
)
from typing_extensions import ParamSpec, Self, is_typeddict
from typing_extensions import ParamSpec, is_typeddict

from pydantic import VERSION, BaseModel

Expand Down
2 changes: 1 addition & 1 deletion nonebot/dependencies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from typing import Any, Generic, TypeVar, cast

import anyio
from exceptiongroup import BaseExceptionGroup, catch
from exceptiongroup import catch

from nonebot.compat import FieldInfo, ModelField, PydanticUndefined
from nonebot.exception import SkippedException
Expand Down
2 changes: 1 addition & 1 deletion nonebot/drivers/none.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import anyio
from anyio.abc import TaskGroup
from exceptiongroup import BaseExceptionGroup, catch
from exceptiongroup import catch

from nonebot.config import Config, Env
from nonebot.consts import WINDOWS
Expand Down
2 changes: 1 addition & 1 deletion nonebot/internal/adapter/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import TYPE_CHECKING, Any, ClassVar, Protocol

import anyio
from exceptiongroup import BaseExceptionGroup, catch
from exceptiongroup import catch

from nonebot.config import Config
from nonebot.exception import MockApiException
Expand Down Expand Up @@ -121,7 +121,7 @@
):
async with anyio.create_task_group() as tg:
for hook in self._calling_api_hook:
tg.start_soon(hook, self, api, data)

Check failure on line 124 in nonebot/internal/adapter/bot.py

View workflow job for this annotation

GitHub Actions / Pyright Lint (pydantic-v2)

Argument of type "T_CallingAPIHook" cannot be assigned to parameter "func" of type "(*PosArgsT@start_soon) -> Coroutine[Any, Any, T_co@start_soon]" in function "start_soon"   Type "T_CallingAPIHook" is not assignable to type "(Self@Bot, str, dict[str, Any]) -> Coroutine[Any, Any, T_co@start_soon]"     Function return type "Awaitable[Any]" is incompatible with type "Coroutine[Any, Any, T_co@start_soon]"       "Awaitable[Any]" is not assignable to "Coroutine[Any, Any, T_co@start_soon]" (reportArgumentType)

Check failure on line 124 in nonebot/internal/adapter/bot.py

View workflow job for this annotation

GitHub Actions / Pyright Lint (pydantic-v1)

Argument of type "T_CallingAPIHook" cannot be assigned to parameter "func" of type "(*PosArgsT@start_soon) -> Coroutine[Any, Any, T_co@start_soon]" in function "start_soon"   Type "T_CallingAPIHook" is not assignable to type "(Self@Bot, str, dict[str, Any]) -> Coroutine[Any, Any, T_co@start_soon]"     Function return type "Awaitable[Any]" is incompatible with type "Coroutine[Any, Any, T_co@start_soon]"       "Awaitable[Any]" is not assignable to "Coroutine[Any, Any, T_co@start_soon]" (reportArgumentType)

if not skip_calling_api:
try:
Expand Down Expand Up @@ -170,7 +170,7 @@
):
async with anyio.create_task_group() as tg:
for hook in self._called_api_hook:
tg.start_soon(hook, self, exception, api, data, result)

Check failure on line 173 in nonebot/internal/adapter/bot.py

View workflow job for this annotation

GitHub Actions / Pyright Lint (pydantic-v2)

Argument of type "T_CalledAPIHook" cannot be assigned to parameter "func" of type "(*PosArgsT@start_soon) -> Coroutine[Any, Any, T_co@start_soon]" in function "start_soon"   Type "T_CalledAPIHook" is not assignable to type "(Self@Bot, Exception | None, str, dict[str, Any], Any) -> Coroutine[Any, Any, T_co@start_soon]"     Function return type "Awaitable[Any]" is incompatible with type "Coroutine[Any, Any, T_co@start_soon]"       "Awaitable[Any]" is not assignable to "Coroutine[Any, Any, T_co@start_soon]" (reportArgumentType)

Check failure on line 173 in nonebot/internal/adapter/bot.py

View workflow job for this annotation

GitHub Actions / Pyright Lint (pydantic-v1)

Argument of type "T_CalledAPIHook" cannot be assigned to parameter "func" of type "(*PosArgsT@start_soon) -> Coroutine[Any, Any, T_co@start_soon]" in function "start_soon"   Type "T_CalledAPIHook" is not assignable to type "(Self@Bot, Exception | None, str, dict[str, Any], Any) -> Coroutine[Any, Any, T_co@start_soon]"     Function return type "Awaitable[Any]" is incompatible with type "Coroutine[Any, Any, T_co@start_soon]"       "Awaitable[Any]" is not assignable to "Coroutine[Any, Any, T_co@start_soon]" (reportArgumentType)

if exception:
raise exception
Expand Down
4 changes: 2 additions & 2 deletions nonebot/internal/adapter/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from typing import ( # noqa: UP035
Any,
Generic,
Self,
SupportsIndex,
Type,
TypeVar,
overload,
)
from typing_extensions import Self

from nonebot.compat import custom_validation, type_validate_python

Expand Down Expand Up @@ -107,7 +107,7 @@

def __init__(
self,
message: str | None | Iterable[TMS] | TMS = None,
message: str | Iterable[TMS] | TMS | None = None,
):
super().__init__()
if message is None:
Expand All @@ -122,7 +122,7 @@
self.extend(self._construct(message)) # pragma: no cover

@classmethod
def template(cls, format_string: str | TM) -> MessageTemplate[Self]:

Check warning on line 125 in nonebot/internal/adapter/message.py

View workflow job for this annotation

GitHub Actions / Pyright Lint (pydantic-v2)

TypeVar "TM" appears only once in generic function signature   Use "Message[TMS@Message]" instead (reportInvalidTypeVarUse)

Check warning on line 125 in nonebot/internal/adapter/message.py

View workflow job for this annotation

GitHub Actions / Pyright Lint (pydantic-v1)

TypeVar "TM" appears only once in generic function signature   Use "Message[TMS@Message]" instead (reportInvalidTypeVarUse)
"""创建消息模板。

用法和 `str.format` 大致相同,支持以 `Message` 对象作为消息模板并输出消息对象。
Expand Down
5 changes: 2 additions & 3 deletions nonebot/internal/driver/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
from collections.abc import AsyncGenerator
from contextlib import AsyncExitStack, asynccontextmanager
from types import TracebackType
from typing import TYPE_CHECKING, Any, ClassVar, TypeAlias
from typing_extensions import Self
from typing import TYPE_CHECKING, Any, ClassVar, Self, TypeAlias

from anyio import CancelScope, create_task_group
from anyio.abc import TaskGroup
from exceptiongroup import BaseExceptionGroup, catch
from exceptiongroup import catch

from nonebot.config import Config, Env
from nonebot.dependencies import Dependent
Expand Down
16 changes: 8 additions & 8 deletions nonebot/internal/driver/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
class Timeout:
"""Request 超时配置。"""

total: float | None | UnsetType = UNSET
connect: float | None | UnsetType = UNSET
read: float | None | UnsetType = UNSET
close: float | None | UnsetType = UNSET
ping: float | None | UnsetType = UNSET
total: float | UnsetType | None = UNSET
connect: float | UnsetType | None = UNSET
read: float | UnsetType | None = UNSET
close: float | UnsetType | None = UNSET
ping: float | UnsetType | None = UNSET


DEFAULT_TIMEOUT = Timeout(total=None, connect=5.0, read=30.0, close=10.0, ping=20.0)
Expand All @@ -31,15 +31,15 @@ class Timeout:
SimpleQuery: TypeAlias = str | int | float
QueryVariable: TypeAlias = SimpleQuery | list[SimpleQuery]
QueryTypes: TypeAlias = (
None | str | Mapping[str, QueryVariable] | list[tuple[str, SimpleQuery]]
str | Mapping[str, QueryVariable] | list[tuple[str, SimpleQuery]] | None
)

HeaderTypes: TypeAlias = (
None | CIMultiDict[str] | dict[str, str] | list[tuple[str, str]]
CIMultiDict[str] | dict[str, str] | list[tuple[str, str]] | None
)

CookieTypes: TypeAlias = (
"None | Cookies | CookieJar | dict[str, str] | list[tuple[str, str]]"
"Cookies | CookieJar | dict[str, str] | list[tuple[str, str]] | None"
)

ContentTypes: TypeAlias = str | bytes | None
Expand Down
4 changes: 2 additions & 2 deletions nonebot/internal/matcher/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
Callable,
ClassVar,
NoReturn,
Self,
Type,
TypeVar,
overload,
)
from typing_extensions import Self
import warnings

from exceptiongroup import BaseExceptionGroup, catch
from exceptiongroup import catch

from nonebot.consts import (
ARG_KEY,
Expand Down
8 changes: 5 additions & 3 deletions nonebot/internal/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
Annotated,
Any,
Literal,
Self,
cast,
get_args,
get_origin,
)
from typing_extensions import Self, override
from typing_extensions import override

import anyio
from exceptiongroup import BaseExceptionGroup, catch
from exceptiongroup import catch
from pydantic.fields import FieldInfo as PydanticFieldInfo

from nonebot.compat import FieldInfo, ModelField, PydanticUndefined
Expand Down Expand Up @@ -97,7 +98,8 @@ async def handler(
return DependsInner(dependency, use_cache=use_cache, validate=validate)


class CacheState(str, Enum):
# Keep Enum string formatting in cache state errors.
class CacheState(str, Enum): # noqa: UP042
"""子依赖缓存状态"""

PENDING = "PENDING"
Expand Down
3 changes: 1 addition & 2 deletions nonebot/internal/permission.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from contextlib import AsyncExitStack
from typing import ClassVar, NoReturn
from typing_extensions import Self
from typing import ClassVar, NoReturn, Self

import anyio

Expand Down
2 changes: 1 addition & 1 deletion nonebot/internal/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import ClassVar, NoReturn

import anyio
from exceptiongroup import BaseExceptionGroup, catch
from exceptiongroup import catch

from nonebot.dependencies import Dependent
from nonebot.exception import SkippedException
Expand Down
2 changes: 1 addition & 1 deletion nonebot/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from typing import TYPE_CHECKING, Any

import anyio
from exceptiongroup import BaseExceptionGroup, catch
from exceptiongroup import catch

from nonebot.dependencies import Dependent
from nonebot.exception import (
Expand Down
6 changes: 1 addition & 5 deletions nonebot/plugin/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from itertools import chain
import json
from pathlib import Path
import tomllib
from types import ModuleType

from nonebot.log import logger
Expand All @@ -20,11 +21,6 @@
from .manager import PluginManager
from .model import Plugin

try: # pragma: py-gte-311
import tomllib # pyright: ignore[reportMissingImports]
except ModuleNotFoundError: # pragma: py-lt-311
import tomli as tomllib # pyright: ignore[reportMissingImports]


def load_plugin(module_path: str | Path) -> Plugin | None:
"""加载单个插件,可以是本地插件或是通过 `pip` 安装的插件。
Expand Down
2 changes: 1 addition & 1 deletion nonebot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

import anyio
import anyio.to_thread
from exceptiongroup import BaseExceptionGroup, catch
from exceptiongroup import catch
from pydantic import BaseModel

from nonebot.log import logger
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ classifiers = [
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
]
requires-python = ">=3.10, <4.0"
requires-python = ">=3.11, <4.0"
dependencies = [
"yarl >=1.7.2, <2.0.0",
"anyio >=4.4.0, <5.0.0",
Expand All @@ -22,7 +22,6 @@ dependencies = [
"exceptiongroup >=1.2.2, <2.0.0",
"python-dotenv >=0.21.0, <2.0.0",
"typing-extensions >=4.6.0, <5.0.0",
"tomli >=2.0.1, <3.0.0; python_version < '3.11'",
"pydantic >=1.10.0, <3.0.0, !=2.5.0, !=2.5.1, !=2.10.0, !=2.10.1",
]

Expand Down Expand Up @@ -127,7 +126,7 @@ mark-parentheses = false
keep-runtime-typing = true

[tool.pyright]
pythonVersion = "3.10"
pythonVersion = "3.11"
pythonPlatform = "All"
defineConstant = { PYDANTIC_V2 = true }
executionEnvironments = [
Expand Down
2 changes: 0 additions & 2 deletions tests/.coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,5 @@ rules =
"sys_platform != 'win32'": py-win32
"sys_platform != 'linux'": py-linux
"sys_platform != 'darwin'": py-darwin
"sys_version_info < (3, 11)": py-gte-311
"sys_version_info >= (3, 11)": py-lt-311
"package_version('pydantic') < (2,)": pydantic-v2
"package_version('pydantic') >= (2,)": pydantic-v1
4 changes: 2 additions & 2 deletions tests/plugins/plugin/matchers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timezone
from datetime import UTC, datetime

from nonebot import (
CommandGroup,
Expand Down Expand Up @@ -33,7 +33,7 @@ async def handler():
return


expire_time = datetime.now(timezone.utc)
expire_time = datetime.now(UTC)
priority = 100
state = {"test": "test"}

Expand Down
1 change: 0 additions & 1 deletion tests/test_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import re
import sys

from exceptiongroup import BaseExceptionGroup
from nonebug import App
import pytest

Expand Down
Loading
Loading