MCPcopy Create free account
hub / github.com/ipython/ipython / update_user_ns

Method update_user_ns

IPython/core/displayhook.py:197–231  ·  view source on GitHub ↗

Update user_ns with various things like _, __, _1, etc.

(self, result)

Source from the content-addressed store, hash-verified

195 print(result_repr.encode(sys.stdout.encoding,'backslashreplace').decode(sys.stdout.encoding))
196
197 def update_user_ns(self, result):
198 """Update user_ns with various things like _, __, _1, etc."""
199
200 # Avoid recursive reference when displaying _oh/Out
201 if self.cache_size and result is not self.shell.user_ns['_oh']:
202 if len(self.shell.user_ns['_oh']) >= self.cache_size and self.do_full_cache:
203 self.cull_cache()
204
205 # Don't overwrite '_' and friends if '_' is in __builtin__
206 # (otherwise we cause buggy behavior for things like gettext). and
207 # do not overwrite _, __ or ___ if one of these has been assigned
208 # by the user.
209 update_unders = True
210 for unders in ['_'*i for i in range(1,4)]:
211 if not unders in self.shell.user_ns:
212 continue
213 if getattr(self, unders) is not self.shell.user_ns.get(unders):
214 update_unders = False
215
216 self.___ = self.__
217 self.__ = self._
218 self._ = result
219
220 if ('_' not in builtin_mod.__dict__) and (update_unders):
221 self.shell.push({'_':self._,
222 '__':self.__,
223 '___':self.___}, interactive=False)
224
225 # hackish access to top-level namespace to create _1,_2... dynamically
226 to_main = {}
227 if self.do_full_cache:
228 new_result = '_%s' % self.prompt_count
229 to_main[new_result] = result
230 self.shell.push(to_main, interactive=False)
231 self.shell.user_ns['_oh'][self.prompt_count] = result
232
233 def fill_exec_result(self, result):
234 if self.exec_result is not None:

Callers 1

__call__Method · 0.95

Calls 2

cull_cacheMethod · 0.95
pushMethod · 0.45

Tested by

no test coverage detected