Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fd1a284

Browse files
committed
fix: CapturedIO.__init__ type annotations to accept Optional[StringIO]
1 parent 77ad39a commit fd1a284

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

IPython/utils/capture.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ class CapturedIO:
7474
above in the same order, and can be invoked simply via ``c()``.
7575
"""
7676

77-
def __init__(self, stdout: StringIO, stderr: StringIO, outputs: Optional[List[Any]]=None):
77+
def __init__(
78+
self,
79+
stdout: Optional[StringIO],
80+
stderr: Optional[StringIO],
81+
outputs: Optional[List[Any]] = None,
82+
):
7883
self._stdout = stdout
7984
self._stderr = stderr
8085
if outputs is None:

tests/test_capture.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,11 @@ def test_capture_output_no_display():
168168
assert hello_stdout == cap.stdout
169169
assert hello_stderr == cap.stderr
170170
assert cap.outputs == []
171+
172+
173+
def test_captured_io_none_streams():
174+
"""CapturedIO accepts None for stdout/stderr and returns empty strings."""
175+
cap = capture.CapturedIO(None, None)
176+
assert cap.stdout == ""
177+
assert cap.stderr == ""
178+
assert cap.outputs == []

0 commit comments

Comments
 (0)