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

Function update_class

IPython/extensions/autoreload.py:380–419  ·  view source on GitHub ↗

Replace stuff in the __dict__ of a class, and upgrade method code objects, and add new methods, if any

(old, new)

Source from the content-addressed store, hash-verified

378
379
380def update_class(old, new):
381 """Replace stuff in the __dict__ of a class, and upgrade
382 method code objects, and add new methods, if any"""
383 for key in list(old.__dict__.keys()):
384 old_obj = getattr(old, key)
385 try:
386 new_obj = getattr(new, key)
387 # explicitly checking that comparison returns True to handle
388 # cases where `==` doesn't return a boolean.
389 if (old_obj == new_obj) is True:
390 continue
391 except AttributeError:
392 # obsolete attribute: remove it
393 try:
394 delattr(old, key)
395 except (AttributeError, TypeError):
396 pass
397 continue
398 except ValueError:
399 # can't compare nested structures containing
400 # numpy arrays using `==`
401 pass
402
403 if update_generic(old_obj, new_obj):
404 continue
405
406 try:
407 setattr(old, key, getattr(new, key))
408 except (AttributeError, TypeError):
409 pass # skip non-writable attributes
410
411 for key in list(new.__dict__.keys()):
412 if key not in list(old.__dict__.keys()):
413 try:
414 setattr(old, key, getattr(new, key))
415 except (AttributeError, TypeError):
416 pass # skip non-writable attributes
417
418 # update all instances of class
419 update_instances(old, new)
420
421
422def update_property(old, new):

Callers

nothing calls this directly

Calls 3

update_genericFunction · 0.85
update_instancesFunction · 0.85
keysMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…