Replace stuff in the __dict__ of a class, and upgrade method code objects, and add new methods, if any
(old, new)
| 378 | |
| 379 | |
| 380 | def 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 | |
| 422 | def update_property(old, new): |
nothing calls this directly
no test coverage detected
searching dependent graphs…