Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4083dd8

Browse files
committed
Fix new mypy confusion about kill_after_timeout type
The refactoring in1ef3365 before this added a new mypy error onnon-Windows platforms, where mypy failed to infer that the type ofkill_after_timeout was `float` (rather than `float | None`) at thepoint in the code where it was used as a captured variable in thenewly introduced communicate() helper.This was even though the variable is never rebound there or in theenclosing scope that introduced it. So introducing and using a newvariable that holds the same reference, which is sufficient to fixthe problem and is the approach taken here, is not a behavioralchange.
1 parent1ef3365 commit4083dd8

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

‎git/cmd.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,8 @@ def execute(
11801180
returnself.AutoInterrupt(proc,command)
11811181

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

11841186
defkill_process(pid:int)->None:
11851187
"""Callback to kill a process.
@@ -1216,7 +1218,7 @@ def communicate() -> Tuple[AnyStr, AnyStr]:
12161218
ifkill_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
ifnotuniversal_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)

[8]ページ先頭

©2009-2025 Movatter.jp