Skip to content

Commit 4083dd8

Browse files
committed
Fix new mypy confusion about kill_after_timeout type
The refactoring in 1ef3365 before this added a new mypy error on non-Windows platforms, where mypy failed to infer that the type of kill_after_timeout was `float` (rather than `float | None`) at the point in the code where it was used as a captured variable in the newly introduced communicate() helper. This was even though the variable is never rebound there or in the enclosing scope that introduced it. So introducing and using a new variable that holds the same reference, which is sufficient to fix the problem and is the approach taken here, is not a behavioral change.
1 parent 1ef3365 commit 4083dd8

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Diff for: git/cmd.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,8 @@ def execute(
11801180
return self.AutoInterrupt(proc, command)
11811181

11821182
if sys.platform != "win32" and kill_after_timeout is not None:
1183+
# Help mypy figure out this is not None even when used inside communicate().
1184+
timeout = kill_after_timeout
11831185

11841186
def kill_process(pid: int) -> None:
11851187
"""Callback to kill a process.
@@ -1216,7 +1218,7 @@ def communicate() -> Tuple[AnyStr, AnyStr]:
12161218
if kill_check.is_set():
12171219
err = 'Timeout: the command "%s" did not complete in %d ' "secs." % (
12181220
" ".join(redacted_command),
1219-
kill_after_timeout,
1221+
timeout,
12201222
)
12211223
if not universal_newlines:
12221224
err = err.encode(defenc)
@@ -1225,7 +1227,7 @@ def communicate() -> Tuple[AnyStr, AnyStr]:
12251227
# END helpers
12261228

12271229
kill_check = threading.Event()
1228-
watchdog = threading.Timer(kill_after_timeout, kill_process, args=(proc.pid,))
1230+
watchdog = threading.Timer(timeout, kill_process, args=(proc.pid,))
12291231
else:
12301232
communicate = proc.communicate
12311233

0 commit comments

Comments
 (0)