Skip to content
Merged
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
10 changes: 2 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,5 @@ report.fail_under = 63
html.show_contexts = true
html.skip_covered = false

[tool.mypy]
show_error_codes = true
strict = true
overrides = [
{ module = [
"pre_commit.*",
], ignore_missing_imports = true },
]
[tool.ty]
environment.python-version = "3.14"
16 changes: 9 additions & 7 deletions src/pre_commit_uv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
# only import built-ins at top level to avoid interpreter startup overhead
import os
import sys
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from collections.abc import Sequence

_original_main = None

Expand Down Expand Up @@ -33,7 +37,7 @@ def _patch() -> None:
if _is_calling_pre_commit() and os.environ.get("DISABLE_PRE_COMMIT_UV_PATCH") is None:
from pre_commit import main # noqa: PLC0415

_original_main, main.main = main.main, _new_main
_original_main, main.main = main.main, _new_main # ty: ignore[invalid-assignment]
if "--version" in sys.argv:
from importlib.metadata import version as _metadata_version # noqa: PLC0415

Expand All @@ -47,16 +51,14 @@ def _patch() -> None:
)


def _new_main(argv: list[str] | None = None) -> int:
def _new_main(argv: Sequence[str] | None = None) -> int:
# imports applied locally to avoid patching import overhead cost
from functools import cache # noqa: PLC0415
from typing import TYPE_CHECKING, cast # noqa: PLC0415
from typing import cast # noqa: PLC0415

from pre_commit.languages import python # noqa: PLC0415

if TYPE_CHECKING:
from collections.abc import Sequence # noqa: PLC0415

from pre_commit.prefix import Prefix # noqa: PLC0415

def _install_environment(
Expand Down Expand Up @@ -126,11 +128,11 @@ def _version_info(exe: str) -> str:

prog = 'import sys;print(".".join(str(p) for p in sys.version_info[0:3]))'
try:
return cast("str", cmd_output(exe, "-S", "-c", prog)[1].strip())
return cmd_output(exe, "-S", "-c", prog)[1].strip()
except CalledProcessError:
return f"<<error retrieving version from {exe}>>"

python.install_environment = _install_environment
python.install_environment = _install_environment # ty: ignore[invalid-assignment]
python._version_info = _version_info # noqa: SLF001
assert _original_main is not None # noqa: S101
return cast("int", _original_main(argv))
4 changes: 2 additions & 2 deletions tox.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ commands = [

[env.type]
description = "run type check on code base"
deps = [ "mypy==1.18.2" ]
commands = [ [ "mypy", "src" ], [ "mypy", "tests" ] ]
deps = [ "ty>=0.0.17" ]
commands = [ [ "ty", "check", "--output-format", "concise", "--error-on-warning", "." ] ]

[env.dev]
description = "generate a DEV environment"
Expand Down