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

Function cleanup_user_ns

tests/test_oinspect.py:360–380  ·  view source on GitHub ↗

On exit delete all the keys that were not in user_ns before entering. It does not restore old values ! Parameters ---------- **kwargs used to update ip.user_ns

(**kwargs)

Source from the content-addressed store, hash-verified

358
359@contextmanager
360def cleanup_user_ns(**kwargs):
361 """
362 On exit delete all the keys that were not in user_ns before entering.
363
364 It does not restore old values !
365
366 Parameters
367 ----------
368
369 **kwargs
370 used to update ip.user_ns
371
372 """
373 try:
374 known = set(ip.user_ns.keys())
375 ip.user_ns.update(kwargs)
376 yield
377 finally:
378 added = set(ip.user_ns.keys()) - known
379 for k in added:
380 del ip.user_ns[k]
381
382
383def test_pinfo_bool_raise():

Callers 4

test_pinfo_bool_raiseFunction · 0.85
test_pinfo_getindexFunction · 0.85
test_qmark_getindexFunction · 0.85

Calls 2

keysMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…