Skip to content

Commit 081dc83

Browse files
authored
🚨 Develop: 完全使用 ruff 替代 isort 与 black (#3151)
1 parent 6dad4d2 commit 081dc83

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1783
-1737
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
"vscode": {
1010
"settings": {
1111
"python.analysis.diagnosticMode": "workspace",
12-
"ruff.organizeImports": false,
1312
"[python]": {
14-
"editor.defaultFormatter": "ms-python.black-formatter",
13+
"editor.defaultFormatter": "charliermarsh.ruff",
1514
"editor.codeActionsOnSave": {
1615
"source.fixAll.ruff": "explicit",
1716
"source.organizeImports": "explicit"
@@ -43,8 +42,6 @@
4342
"extensions": [
4443
"ms-python.python",
4544
"ms-python.vscode-pylance",
46-
"ms-python.isort",
47-
"ms-python.black-formatter",
4845
"charliermarsh.ruff",
4946
"EditorConfig.EditorConfig",
5047
"esbenp.prettier-vscode",

.pre-commit-config.yaml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,12 @@ ci:
77
autoupdate_commit_msg: ":arrow_up: auto update by pre-commit hooks"
88
repos:
99
- repo: https://github.com/astral-sh/ruff-pre-commit
10-
rev: v0.7.2
10+
rev: v0.8.1
1111
hooks:
1212
- id: ruff
13-
args: [--fix, --exit-non-zero-on-fix]
13+
args: [--fix]
1414
stages: [pre-commit]
15-
16-
- repo: https://github.com/pycqa/isort
17-
rev: 5.13.2
18-
hooks:
19-
- id: isort
20-
stages: [pre-commit]
21-
22-
- repo: https://github.com/psf/black
23-
rev: 24.10.0
24-
hooks:
25-
- id: black
15+
- id: ruff-format
2616
stages: [pre-commit]
2717

2818
- repo: https://github.com/nonebot/nonemoji

envs/pydantic-v1/poetry.lock

Lines changed: 325 additions & 288 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

envs/pydantic-v2/poetry.lock

Lines changed: 328 additions & 291 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

envs/test/poetry.lock

Lines changed: 99 additions & 69 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nonebot/__init__.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,18 @@
4545
description: nonebot 模块
4646
"""
4747

48-
import os
4948
from importlib.metadata import version
50-
from typing import Any, Union, TypeVar, Optional, overload
49+
import os
50+
from typing import Any, Optional, TypeVar, Union, overload
5151

5252
import loguru
5353

54+
from nonebot.adapters import Adapter, Bot
5455
from nonebot.compat import model_dump
56+
from nonebot.config import DOTENV_TYPE, Config, Env
57+
from nonebot.drivers import ASGIMixin, Driver, combine_driver
5558
from nonebot.log import logger as logger
56-
from nonebot.adapters import Bot, Adapter
57-
from nonebot.config import DOTENV_TYPE, Env, Config
5859
from nonebot.utils import escape_tag, resolve_dot_notation
59-
from nonebot.drivers import Driver, ASGIMixin, combine_driver
6060

6161
try:
6262
__version__ = version("nonebot2")
@@ -337,31 +337,31 @@ def run(*args: Any, **kwargs: Any) -> None:
337337
get_driver().run(*args, **kwargs)
338338

339339

340-
from nonebot.plugin import on as on
341-
from nonebot.plugin import on_type as on_type
342-
from nonebot.plugin import require as require
343-
from nonebot.plugin import on_regex as on_regex
344-
from nonebot.plugin import on_notice as on_notice
345-
from nonebot.plugin import get_plugin as get_plugin
346-
from nonebot.plugin import on_command as on_command
347-
from nonebot.plugin import on_keyword as on_keyword
348-
from nonebot.plugin import on_message as on_message
349-
from nonebot.plugin import on_request as on_request
350-
from nonebot.plugin import load_plugin as load_plugin
351-
from nonebot.plugin import on_endswith as on_endswith
352340
from nonebot.plugin import CommandGroup as CommandGroup
353341
from nonebot.plugin import MatcherGroup as MatcherGroup
342+
from nonebot.plugin import get_available_plugin_names as get_available_plugin_names
343+
from nonebot.plugin import get_loaded_plugins as get_loaded_plugins
344+
from nonebot.plugin import get_plugin as get_plugin
345+
from nonebot.plugin import get_plugin_by_module_name as get_plugin_by_module_name
346+
from nonebot.plugin import get_plugin_config as get_plugin_config
347+
from nonebot.plugin import load_all_plugins as load_all_plugins
348+
from nonebot.plugin import load_builtin_plugin as load_builtin_plugin
349+
from nonebot.plugin import load_builtin_plugins as load_builtin_plugins
350+
from nonebot.plugin import load_from_json as load_from_json
351+
from nonebot.plugin import load_from_toml as load_from_toml
352+
from nonebot.plugin import load_plugin as load_plugin
354353
from nonebot.plugin import load_plugins as load_plugins
354+
from nonebot.plugin import on as on
355+
from nonebot.plugin import on_command as on_command
356+
from nonebot.plugin import on_endswith as on_endswith
355357
from nonebot.plugin import on_fullmatch as on_fullmatch
358+
from nonebot.plugin import on_keyword as on_keyword
359+
from nonebot.plugin import on_message as on_message
356360
from nonebot.plugin import on_metaevent as on_metaevent
357-
from nonebot.plugin import on_startswith as on_startswith
358-
from nonebot.plugin import load_from_json as load_from_json
359-
from nonebot.plugin import load_from_toml as load_from_toml
360-
from nonebot.plugin import load_all_plugins as load_all_plugins
361+
from nonebot.plugin import on_notice as on_notice
362+
from nonebot.plugin import on_regex as on_regex
363+
from nonebot.plugin import on_request as on_request
361364
from nonebot.plugin import on_shell_command as on_shell_command
362-
from nonebot.plugin import get_plugin_config as get_plugin_config
363-
from nonebot.plugin import get_loaded_plugins as get_loaded_plugins
364-
from nonebot.plugin import load_builtin_plugin as load_builtin_plugin
365-
from nonebot.plugin import load_builtin_plugins as load_builtin_plugins
366-
from nonebot.plugin import get_plugin_by_module_name as get_plugin_by_module_name
367-
from nonebot.plugin import get_available_plugin_names as get_available_plugin_names
365+
from nonebot.plugin import on_startswith as on_startswith
366+
from nonebot.plugin import on_type as on_type
367+
from nonebot.plugin import require as require

nonebot/adapters/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
description: nonebot.adapters 模块
1010
"""
1111

12+
from nonebot.internal.adapter import Adapter as Adapter
1213
from nonebot.internal.adapter import Bot as Bot
1314
from nonebot.internal.adapter import Event as Event
14-
from nonebot.internal.adapter import Adapter as Adapter
1515
from nonebot.internal.adapter import Message as Message
1616
from nonebot.internal.adapter import MessageSegment as MessageSegment
1717
from nonebot.internal.adapter import MessageTemplate as MessageTemplate

nonebot/compat.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@
1010
"""
1111

1212
from collections.abc import Generator
13-
from functools import cached_property
1413
from dataclasses import dataclass, is_dataclass
15-
from typing_extensions import Self, get_args, get_origin, is_typeddict
14+
from functools import cached_property
1615
from typing import (
1716
TYPE_CHECKING,
17+
Annotated,
1818
Any,
19-
Union,
20-
Generic,
21-
TypeVar,
2219
Callable,
20+
Generic,
2321
Optional,
2422
Protocol,
25-
Annotated,
23+
TypeVar,
24+
Union,
2625
overload,
2726
)
27+
from typing_extensions import Self, get_args, get_origin, is_typeddict
2828

2929
from pydantic import VERSION, BaseModel
3030

@@ -44,21 +44,21 @@ def __get_validators__(cls) -> Generator[Callable[..., Any], None, None]: ...
4444

4545

4646
__all__ = (
47-
"Required",
48-
"PydanticUndefined",
49-
"PydanticUndefinedType",
50-
"ConfigDict",
5147
"DEFAULT_CONFIG",
48+
"ConfigDict",
5249
"FieldInfo",
5350
"ModelField",
51+
"PydanticUndefined",
52+
"PydanticUndefinedType",
53+
"Required",
5454
"TypeAdapter",
55+
"custom_validation",
5556
"extract_field_info",
56-
"model_fields",
5757
"model_config",
5858
"model_dump",
59-
"type_validate_python",
59+
"model_fields",
6060
"type_validate_json",
61-
"custom_validation",
61+
"type_validate_python",
6262
)
6363

6464
__autodoc__ = {
@@ -70,9 +70,9 @@ def __get_validators__(cls) -> Generator[Callable[..., Any], None, None]: ...
7070
if PYDANTIC_V2: # pragma: pydantic-v2
7171
from pydantic import GetCoreSchemaHandler
7272
from pydantic import TypeAdapter as TypeAdapter
73-
from pydantic_core import CoreSchema, core_schema
7473
from pydantic._internal._repr import display_as_type
7574
from pydantic.fields import FieldInfo as BaseFieldInfo
75+
from pydantic_core import CoreSchema, core_schema
7676

7777
Required = Ellipsis
7878
"""Alias of Ellipsis for compatibility with pydantic v1"""
@@ -253,9 +253,8 @@ def custom_validation(class_: type["CVC"]) -> type["CVC"]:
253253
return class_
254254

255255
else: # pragma: pydantic-v1
256-
from pydantic import Extra
257-
from pydantic import parse_obj_as, parse_raw_as
258256
from pydantic import BaseConfig as PydanticConfig
257+
from pydantic import Extra, parse_obj_as, parse_raw_as
259258
from pydantic.fields import FieldInfo as BaseFieldInfo
260259
from pydantic.fields import ModelField as BaseModelField
261260
from pydantic.schema import get_annotation_from_field_info

nonebot/config.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,20 @@
1313
description: nonebot.config 模块
1414
"""
1515

16-
import os
1716
import abc
18-
import json
19-
from pathlib import Path
17+
from collections.abc import Mapping
2018
from datetime import timedelta
2119
from ipaddress import IPv4Address
22-
from collections.abc import Mapping
23-
from typing import TYPE_CHECKING, Any, Union, Optional
20+
import json
21+
import os
22+
from pathlib import Path
23+
from typing import TYPE_CHECKING, Any, Optional, Union
2424
from typing_extensions import TypeAlias, get_args, get_origin
2525

2626
from dotenv import dotenv_values
27-
from pydantic import Field, BaseModel
27+
from pydantic import BaseModel, Field
2828
from pydantic.networks import IPvAnyAddress
2929

30-
from nonebot.log import logger
31-
from nonebot.typing import origin_is_union
32-
from nonebot.utils import deep_update, type_is_complex, lenient_issubclass
3330
from nonebot.compat import (
3431
PYDANTIC_V2,
3532
ConfigDict,
@@ -39,6 +36,9 @@
3936
model_config,
4037
model_fields,
4138
)
39+
from nonebot.log import logger
40+
from nonebot.typing import origin_is_union
41+
from nonebot.utils import deep_update, lenient_issubclass, type_is_complex
4242

4343
DOTENV_TYPE: TypeAlias = Union[
4444
Path, str, list[Union[Path, str]], tuple[Union[Path, str], ...]

nonebot/dependencies/__init__.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@
88
"""
99

1010
import abc
11-
import inspect
11+
from collections.abc import Awaitable, Iterable
12+
from dataclasses import dataclass, field
1213
from functools import partial
13-
from dataclasses import field, dataclass
14-
from collections.abc import Iterable, Awaitable
15-
from typing import Any, Generic, TypeVar, Callable, Optional, cast
14+
import inspect
15+
from typing import Any, Callable, Generic, Optional, TypeVar, cast
1616

1717
import anyio
1818
from exceptiongroup import BaseExceptionGroup, catch
1919

20+
from nonebot.compat import FieldInfo, ModelField, PydanticUndefined
21+
from nonebot.exception import SkippedException
2022
from nonebot.log import logger
2123
from nonebot.typing import _DependentCallable
22-
from nonebot.exception import SkippedException
23-
from nonebot.compat import FieldInfo, ModelField, PydanticUndefined
2424
from nonebot.utils import (
25-
run_sync,
26-
run_coro_with_shield,
27-
is_coroutine_callable,
2825
flatten_exception_group,
26+
is_coroutine_callable,
27+
run_coro_with_shield,
28+
run_sync,
2929
)
3030

3131
from .utils import check_field_type, get_typed_signature

0 commit comments

Comments
 (0)