Skip to content

Commit b1a8539

Browse files
authored
Merge pull request #10425 from pradyunsg/cleanup-logging
Simplify `_is_broken_pipe_error` definition
2 parents f7a8a60 + fd1289b commit b1a8539

File tree

1 file changed

+7
-25
lines changed

1 file changed

+7
-25
lines changed

src/pip/_internal/utils/logging.py

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,36 +35,18 @@ class BrokenStdoutLoggingError(Exception):
3535
Raised if BrokenPipeError occurs for the stdout stream while logging.
3636
"""
3737

38-
pass
3938

39+
def _is_broken_pipe_error(exc_class: Type[BaseException], exc: BaseException) -> bool:
40+
if exc_class is BrokenPipeError:
41+
return True
4042

41-
# BrokenPipeError manifests differently in Windows and non-Windows.
42-
if WINDOWS:
43-
# In Windows, a broken pipe can show up as EINVAL rather than EPIPE:
43+
# On Windows, a broken pipe can show up as EINVAL rather than EPIPE:
4444
# https://bugs.python.org/issue19612
4545
# https://bugs.python.org/issue30418
46-
def _is_broken_pipe_error(
47-
exc_class: Type[BaseException], exc: BaseException
48-
) -> bool:
49-
"""See the docstring for non-Windows below."""
50-
return (exc_class is BrokenPipeError) or (
51-
isinstance(exc, OSError) and exc.errno in (errno.EINVAL, errno.EPIPE)
52-
)
53-
54-
55-
else:
56-
# Then we are in the non-Windows case.
57-
def _is_broken_pipe_error(
58-
exc_class: Type[BaseException], exc: BaseException
59-
) -> bool:
60-
"""
61-
Return whether an exception is a broken pipe error.
46+
if not WINDOWS:
47+
return False
6248

63-
Args:
64-
exc_class: an exception class.
65-
exc: an exception instance.
66-
"""
67-
return exc_class is BrokenPipeError
49+
return isinstance(exc, OSError) and exc.errno in (errno.EINVAL, errno.EPIPE)
6850

6951

7052
@contextlib.contextmanager

0 commit comments

Comments
 (0)