Skip to content

Commit 3e73779

Browse files
authored
Migrate type checking from mypy to ty (#117)
1 parent 8987d91 commit 3e73779

3 files changed

Lines changed: 13 additions & 17 deletions

File tree

pyproject.toml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,5 @@ report.fail_under = 63
128128
html.show_contexts = true
129129
html.skip_covered = false
130130

131-
[tool.mypy]
132-
show_error_codes = true
133-
strict = true
134-
overrides = [
135-
{ module = [
136-
"pre_commit.*",
137-
], ignore_missing_imports = true },
138-
]
131+
[tool.ty]
132+
environment.python-version = "3.14"

src/pre_commit_uv/__init__.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
# only import built-ins at top level to avoid interpreter startup overhead
66
import os
77
import sys
8+
from typing import TYPE_CHECKING
9+
10+
if TYPE_CHECKING:
11+
from collections.abc import Sequence
812

913
_original_main = None
1014

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

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

@@ -47,16 +51,14 @@ def _patch() -> None:
4751
)
4852

4953

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

5559
from pre_commit.languages import python # noqa: PLC0415
5660

5761
if TYPE_CHECKING:
58-
from collections.abc import Sequence # noqa: PLC0415
59-
6062
from pre_commit.prefix import Prefix # noqa: PLC0415
6163

6264
def _install_environment(
@@ -126,11 +128,11 @@ def _version_info(exe: str) -> str:
126128

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

133-
python.install_environment = _install_environment
135+
python.install_environment = _install_environment # ty: ignore[invalid-assignment]
134136
python._version_info = _version_info # noqa: SLF001
135137
assert _original_main is not None # noqa: S101
136138
return cast("int", _original_main(argv))

tox.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ commands = [
5353

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

5959
[env.dev]
6060
description = "generate a DEV environment"

0 commit comments

Comments
 (0)