From 98d5fe9f043ec3753348a6a730d851df6b412032 Mon Sep 17 00:00:00 2001 From: uy/sun Date: Wed, 18 Dec 2024 13:14:09 +0800 Subject: [PATCH] =?UTF-8?q?style:=20=E6=9B=B4=E6=96=B0=20ruff=20=E5=92=8C?= =?UTF-8?q?=20pyright=20=E9=85=8D=E7=BD=AE=20(#329)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增 flake8-type-checking 规则,并更新 ruff 版本。 --- .pre-commit-config.yaml | 6 ++---- pyproject.toml | 8 ++++---- src/providers/validation/__init__.py | 6 ++++-- src/providers/validation/utils.py | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 09c56bf3..67b76175 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,11 +6,10 @@ ci: autoupdate_commit_msg: "chore: auto update by pre-commit hooks" repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.0 + rev: v0.8.3 hooks: - id: ruff - args: [--fix, --exit-non-zero-on-fix] - stages: [pre-commit] + args: [--fix] - id: ruff-format - repo: https://github.com/pre-commit/mirrors-prettier @@ -18,4 +17,3 @@ repos: hooks: - id: prettier types_or: [javascript, jsx, ts, tsx, markdown, yaml, json] - stages: [pre-commit] diff --git a/pyproject.toml b/pyproject.toml index 61f1e6c1..99fd9971 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,17 +50,17 @@ store-test = "python -m src.providers.store_test" docker-test = "python -m src.providers.docker_test" [tool.pyright] -pythonVersion = "3.12" +pythonVersion = "3.13" pythonPlatform = "All" typeCheckingMode = "standard" [tool.ruff] line-length = 88 -target-version = "py312" +target-version = "py313" [tool.ruff.lint] select = [ - "F", # Pyflakes + "F", # pyflakes "W", # pycodestyle warnings "E", # pycodestyle errors "UP", # pyupgrade @@ -71,13 +71,13 @@ select = [ "PYI", # flake8-pyi "PT", # flake8-pytest-style "Q", # flake8-quotes + "TC", # flake8-type-checking "RUF", # Ruff-specific rules "I", # isort ] ignore = [ "E402", # module-import-not-at-top-of-file "E501", # line-too-long - "UP037", # quoted-annotation "RUF001", # ambiguous-unicode-character-string "RUF002", # ambiguous-unicode-character-docstring "RUF003", # ambiguous-unicode-character-comment diff --git a/src/providers/validation/__init__.py b/src/providers/validation/__init__.py index d9d30694..61d36116 100644 --- a/src/providers/validation/__init__.py +++ b/src/providers/validation/__init__.py @@ -1,9 +1,8 @@ """验证数据是否符合规范""" -from typing import Any +from typing import TYPE_CHECKING, Any from pydantic import ValidationError -from pydantic_core import ErrorDetails from .models import ( AdapterPublishInfo, @@ -16,6 +15,9 @@ from .models import ValidationDict as ValidationDict from .utils import translate_errors +if TYPE_CHECKING: + from pydantic_core import ErrorDetails + validation_model_map: dict[PublishType, type[PublishInfoModels]] = { PublishType.BOT: BotPublishInfo, PublishType.ADAPTER: AdapterPublishInfo, diff --git a/src/providers/validation/utils.py b/src/providers/validation/utils.py index ee7b4422..bf8875d3 100644 --- a/src/providers/validation/utils.py +++ b/src/providers/validation/utils.py @@ -46,7 +46,7 @@ def resolve_adapter_name(name: str) -> str: def translate_errors(errors: list["ErrorDetails"]) -> list["ErrorDetails"]: """翻译 Pydantic 错误信息""" - new_errors: list["ErrorDetails"] = [] + new_errors: list[ErrorDetails] = [] for error in errors: translation = MESSAGE_TRANSLATIONS.get(error["type"]) if translation: