55# only import built-ins at top level to avoid interpreter startup overhead
66import os
77import 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 ))
0 commit comments