@@ -4026,10 +4026,8 @@ def __init__(self, shell: InteractiveShell, channel="stdout"):
40264026
40274027 Parameters
40284028 ----------
4029- outputs : dict
4030- Dictionary to store captured outputs, with execution count as key.
4031- execution_count : int
4032- The current cell execution number.
4029+ shell : InteractiveShell
4030+ The shell instance
40334031 channel : str, optional
40344032 Output channel to capture (default: 'stdout').
40354033 """
@@ -4039,6 +4037,9 @@ def __init__(self, shell: InteractiveShell, channel="stdout"):
40394037 setattr (sys , channel , self ) # Redirect stdout to this instance
40404038 self ._closed = False
40414039
4040+ # Store original methods and attributes for delegation
4041+ self ._original_attrs = dir (self .ostream )
4042+
40424043 def write (self , data ):
40434044 """Write data to both the original stdout and the capture dictionary."""
40444045 self .ostream .write (data ) # Display in notebook
@@ -4077,6 +4078,14 @@ def close(self):
40774078 setattr (sys , self .channel , self .ostream )
40784079 self ._closed = True
40794080
4081+ def __getattr__ (self , name ):
4082+ """Delegate any other attribute access to the original stream."""
4083+ if name in self ._original_attrs :
4084+ return getattr (self .ostream , name )
4085+ raise AttributeError (
4086+ f"'{ self .__class__ .__name__ } ' object has no attribute '{ name } '"
4087+ )
4088+
40804089
40814090class InteractiveShellABC (metaclass = abc .ABCMeta ):
40824091 """An abstract base class for InteractiveShell."""
0 commit comments