Fix safe readlines: AttributeError: 'NoneType' object has no attribute 'readlines' (#5646)

* fix

* news

* fix

---------

Co-authored-by: a <1@1.1>
This commit is contained in:
Andy Kipp 2024-08-08 14:26:33 +02:00 committed by GitHub
parent c0e0687376
commit a1846d0579
Failed to generate hash of commit
2 changed files with 26 additions and 1 deletions

View file

@ -0,0 +1,23 @@
**Added:**
* <news item>
**Changed:**
* <news item>
**Deprecated:**
* <news item>
**Removed:**
* <news item>
**Fixed:**
* Fixed exception "object has no attribute readlines" in case of redirect callable alias output.
**Security:**
* <news item>

View file

@ -62,6 +62,8 @@ def SIGNAL_MESSAGES():
def safe_readlines(handle, hint=-1):
"""Attempts to read lines without throwing an error."""
if handle is None:
return []
try:
lines = handle.readlines(hint)
except OSError:
@ -276,7 +278,7 @@ class CommandPipeline:
lines = b.splitlines(keepends=True)
yield from lines
self.end(tee_output=False)
elif self.captured == "stdout":
elif self.captured == "stdout" and stdout is not None:
b = stdout.read()
s = self._decode_uninew(b, universal_newlines=True)
self.lines = s.splitlines(keepends=True)