From e070854a563d7d758c050d59061ef59e177351c3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 16 Mar 2026 20:10:13 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v5.0.0 → v6.0.0](https://github.com/pre-commit/pre-commit-hooks/compare/v5.0.0...v6.0.0) - [github.com/astral-sh/ruff-pre-commit: v0.11.2 → v0.15.6](https://github.com/astral-sh/ruff-pre-commit/compare/v0.11.2...v0.15.6) - [github.com/psf/black-pre-commit-mirror: 25.1.0 → 26.3.1](https://github.com/psf/black-pre-commit-mirror/compare/25.1.0...26.3.1) - [github.com/codespell-project/codespell: v2.4.1 → v2.4.2](https://github.com/codespell-project/codespell/compare/v2.4.1...v2.4.2) - [github.com/alessandrojcm/commitlint-pre-commit-hook: v9.22.0 → v9.24.0](https://github.com/alessandrojcm/commitlint-pre-commit-hook/compare/v9.22.0...v9.24.0) --- .pre-commit-config.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4e28bc8..16761b2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ default_install_hook_types: [pre-commit, commit-msg] repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 + rev: v6.0.0 hooks: - id: no-commit-to-branch - id: check-added-large-files @@ -22,25 +22,25 @@ repos: - id: trailing-whitespace # ruff must before black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.11.2 + rev: v0.15.6 hooks: - id: ruff alias: ruff # NOTE: don't change this alias, it's used in `ver_sync.py`, keep consistent with `pyproject.toml` args: [--fix, --exit-non-zero-on-fix] - repo: https://github.com/psf/black-pre-commit-mirror - rev: 25.1.0 + rev: 26.3.1 hooks: - id: black alias: black # NOTE: don't change this alias, it's used in `ver_sync.py`, keep consistent with `pyproject.toml` - repo: https://github.com/codespell-project/codespell - rev: v2.4.1 + rev: v2.4.2 hooks: - id: codespell alias: codespell # NOTE: don't change this alias, it's used in `ver_sync.py`, keep consistent with `pyproject.toml` additional_dependencies: - tomli - repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook - rev: v9.22.0 + rev: v9.24.0 hooks: - id: commitlint stages: [commit-msg] From b5d105fce822d01f72e9b196beb7703ccd4d441e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 16 Mar 2026 20:12:13 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pyproject.toml | 6 +++--- scripts/pre_commit_scripts/ver_sync.py | 1 - src/fastapi_proxy_lib/core/_tool.py | 26 +++++++---------------- src/fastapi_proxy_lib/fastapi/__init__.py | 6 ++---- tests/conftest.py | 2 +- 5 files changed, 14 insertions(+), 27 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9bd2d00..936f0b6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,9 +84,9 @@ dependencies = [ # NOTE: 👇 # The versions of `black`, `ruff`, `codespell`, must be consistent with the `.pre-commit-config.yaml`. # Don't edit them manually, use `pre-commit run ver_sync` instead. - "black==25.1.0", - "ruff==0.11.2", - "codespell==2.4.1", + "black==26.3.1", + "ruff==0.15.6", + "codespell==2.4.2", # Don't write comments on these lines, because they will be removed by `pre-commit run ver_sync`. # NOTE: 👆 diff --git a/scripts/pre_commit_scripts/ver_sync.py b/scripts/pre_commit_scripts/ver_sync.py index 9e4cca6..a3b2670 100644 --- a/scripts/pre_commit_scripts/ver_sync.py +++ b/scripts/pre_commit_scripts/ver_sync.py @@ -2,7 +2,6 @@ """Maintain lint tools version consistency between `.pre-commit-config.yaml` and `pyproject.toml`.""" - # https://packaging.pypa.io/en/stable/requirements.html # https://yaml.readthedocs.io/en/latest/example/ # https://tomlkit.readthedocs.io/en/latest/quickstart/ diff --git a/src/fastapi_proxy_lib/core/_tool.py b/src/fastapi_proxy_lib/core/_tool.py index c3c72f6..f647cbf 100644 --- a/src/fastapi_proxy_lib/core/_tool.py +++ b/src/fastapi_proxy_lib/core/_tool.py @@ -204,39 +204,31 @@ def check_base_url(base_url: Union[httpx.URL, str], /) -> httpx.URL: ) if not base_url.scheme or not base_url.netloc: - raise BaseURLError( - dedent( - f"""\ + raise BaseURLError(dedent(f"""\ `base_url` must contain scheme and netloc, e.g. {example_url} got: {base_url}\ - """ - ) - ) + """)) # NOTE: 尽量用 URL.copy_with() 来修改URL,而不是 URL.join(),因为后者性能较差 if base_url.query or base_url.fragment: base_url = base_url.copy_with(query=None, fragment=None) warnings.warn( - dedent( - f"""\ + dedent(f"""\ `base_url` should not contain `query` or `fragment`, which will be ignored. The `base_url` will be treated as: {base_url}\ - """ - ), + """), stacklevel=2, ) # 我们在这里强制要求 base_url 以"/"结尾是有原因的: # 因为 RouterHelper 生成的路由是以"/"结尾的,在反向代理时 # "/" 之后后路径参数将会被拼接到这个 base_url 后面 if not str(base_url).endswith("/"): - msg = dedent( - f"""\ + msg = dedent(f"""\ `base_url` must ends with "/", may be you mean: {base_url}/\ - """ - ) + """) raise BaseURLError(msg) return base_url @@ -424,8 +416,7 @@ def warn_for_none_filter( Else will just return the original argument `proxy_filter`. """ if proxy_filter is None: - msg = dedent( - """\ + msg = dedent("""\ The `proxy_filter` is None, which means no filter will be used. It is not recommended, because it may cause security issues. @@ -433,8 +424,7 @@ def warn_for_none_filter( - if the host of url is ip address, and is not global ip address. More info: https://wsh032.github.io/fastapi-proxy-lib/Usage/Security/ - """ - ) + """) warnings.warn(msg, stacklevel=3) return default_proxy_filter else: diff --git a/src/fastapi_proxy_lib/fastapi/__init__.py b/src/fastapi_proxy_lib/fastapi/__init__.py index ffd872c..5ca1c2e 100644 --- a/src/fastapi_proxy_lib/fastapi/__init__.py +++ b/src/fastapi_proxy_lib/fastapi/__init__.py @@ -9,11 +9,9 @@ from textwrap import dedent if find_spec("fastapi") is None: # pragma: no cover # 无法测试 - msg: str = dedent( - """\ + msg: str = dedent("""\ `fastapi` is not installed. `fastapi_proxy_lib.fastapi` module requires installing `fastapi` first: pip install fastapi-proxy-lib[standard] - """ - ) + """) raise RuntimeError(msg) diff --git a/tests/conftest.py b/tests/conftest.py index 817bdad..8183552 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,4 @@ -# ruff: noqa: ANN201, ANN001 +# ruff: noqa: ANN201 # pyright: reportMissingParameterType=false # 返回值标注太麻烦,让pyright自己推断