MCPcopy Index your code
hub / github.com/ipython/ipython / update_user_ns

Method update_user_ns

IPython/core/displayhook.py:210–244  ·  view source on GitHub ↗

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

(self, result)

Source from the content-addressed store, hash-verified

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

Callers 1

__call__Method · 0.95

Calls 3

cull_cacheMethod · 0.95
getMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected