File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed
Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -109,18 +109,24 @@ def get_interpreter(config, locals_=None):
109109 if config .scroll_auto_import :
110110
111111 locals_ = locals_ if locals_ is not None else {}
112+ autoimported = []
112113
113114 class AutoImporter (dict ):
114115 def __getitem__ (self , item ):
115116 if item in locals_ :
116117 return locals_ [item ]
117118 else :
118119 try :
119- return __import__ (item )
120+ module = __import__ (item )
121+ autoimported .append (item )
122+ return module
120123 except ImportError :
121124 raise KeyError (item )
122125 def __setitem__ (self , item , value ):
123126 locals_ [item ] = value
127+ @property
128+ def autoimported (self ):
129+ return autoimported
124130
125131 ns = AutoImporter ()
126132 return code .InteractiveInterpreter (locals = ns )
@@ -843,8 +849,9 @@ def reevaluate(self, insert_into_history=False):
843849
844850 def getstdout (self ):
845851 lines = self .lines_for_display + [self .current_line_formatted ]
846- s = '\n ' .join ([x .s if isinstance (x , FmtStr ) else x
847- for x in lines ]) if lines else ''
852+ s = '\n ' .join (['%simport %s' % (self .ps1 , name ) for name in self .interp .locals .autoimported ] if self .config .scroll_auto_import else [] +
853+ [x .s if isinstance (x , FmtStr ) else x for x in lines ]
854+ ) if lines else ''
848855 return s
849856 def send_to_external_editor (self , filename = None ):
850857 editor = os .environ .get ('VISUAL' , os .environ .get ('EDITOR' , 'vim' ))
You can’t perform that action at this time.
0 commit comments