diff --git a/src/pip/_internal/cli/req_command.py b/src/pip/_internal/cli/req_command.py index dc1328ff019..cc3a5ef639e 100644 --- a/src/pip/_internal/cli/req_command.py +++ b/src/pip/_internal/cli/req_command.py @@ -10,7 +10,7 @@ import logging from functools import partial from optparse import Values -from typing import Any +from typing import Any, Callable, TypeVar from pip._internal.build_env import SubprocessBuildEnvironmentInstaller from pip._internal.cache import WheelCache @@ -51,7 +51,12 @@ ] -def with_cleanup(func: Any) -> Any: +_CommandT = TypeVar("_CommandT", bound="RequirementCommand") + + +def with_cleanup( + func: Callable[[_CommandT, Values, list[str]], int], +) -> Callable[[_CommandT, Values, list[str]], int]: """Decorator for common logic related to managing temporary directories. """ @@ -60,9 +65,7 @@ def configure_tempdir_registry(registry: TempDirectoryTypeRegistry) -> None: for t in KEEPABLE_TEMPDIR_TYPES: registry.set_delete(t, False) - def wrapper( - self: RequirementCommand, options: Values, args: list[Any] - ) -> int | None: + def wrapper(self: _CommandT, options: Values, args: list[str]) -> int: assert self.tempdir_registry is not None if options.no_clean: configure_tempdir_registry(self.tempdir_registry)