Skip to content

Commit 4dd68aa

Browse files
authored
refactor: Improve the typing of the with_cleanup decorator (#13621)
Improve the typing of the with_cleanup decorator, as used by the download, install, lock, and wheel commands.
1 parent 16d50e9 commit 4dd68aa

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/pip/_internal/cli/req_command.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import os
1212
from functools import partial
1313
from optparse import Values
14-
from typing import Any
14+
from typing import Any, Callable, TypeVar
1515

1616
from pip._internal.build_env import SubprocessBuildEnvironmentInstaller
1717
from pip._internal.cache import WheelCache
@@ -62,7 +62,12 @@ def should_ignore_regular_constraints(options: Values) -> bool:
6262
]
6363

6464

65-
def with_cleanup(func: Any) -> Any:
65+
_CommandT = TypeVar("_CommandT", bound="RequirementCommand")
66+
67+
68+
def with_cleanup(
69+
func: Callable[[_CommandT, Values, list[str]], int],
70+
) -> Callable[[_CommandT, Values, list[str]], int]:
6671
"""Decorator for common logic related to managing temporary
6772
directories.
6873
"""
@@ -71,9 +76,7 @@ def configure_tempdir_registry(registry: TempDirectoryTypeRegistry) -> None:
7176
for t in KEEPABLE_TEMPDIR_TYPES:
7277
registry.set_delete(t, False)
7378

74-
def wrapper(
75-
self: RequirementCommand, options: Values, args: list[Any]
76-
) -> int | None:
79+
def wrapper(self: _CommandT, options: Values, args: list[str]) -> int:
7780
assert self.tempdir_registry is not None
7881
if options.no_clean:
7982
configure_tempdir_registry(self.tempdir_registry)

0 commit comments

Comments
 (0)