Replace stuff in the __dict__ of a class, and upgrade method code objects, and add new methods, if any
(old, new)
| 281 | |
| 282 | |
| 283 | def update_class(old, new): |
| 284 | """Replace stuff in the __dict__ of a class, and upgrade |
| 285 | method code objects, and add new methods, if any""" |
| 286 | for key in list(old.__dict__.keys()): |
| 287 | old_obj = getattr(old, key) |
| 288 | try: |
| 289 | new_obj = getattr(new, key) |
| 290 | # explicitly checking that comparison returns True to handle |
| 291 | # cases where `==` doesn't return a boolean. |
| 292 | if (old_obj == new_obj) is True: |
| 293 | continue |
| 294 | except AttributeError: |
| 295 | # obsolete attribute: remove it |
| 296 | try: |
| 297 | delattr(old, key) |
| 298 | except (AttributeError, TypeError): |
| 299 | pass |
| 300 | continue |
| 301 | |
| 302 | if update_generic(old_obj, new_obj): continue |
| 303 | |
| 304 | try: |
| 305 | setattr(old, key, getattr(new, key)) |
| 306 | except (AttributeError, TypeError): |
| 307 | pass # skip non-writable attributes |
| 308 | |
| 309 | for key in list(new.__dict__.keys()): |
| 310 | if key not in list(old.__dict__.keys()): |
| 311 | try: |
| 312 | setattr(old, key, getattr(new, key)) |
| 313 | except (AttributeError, TypeError): |
| 314 | pass # skip non-writable attributes |
| 315 | |
| 316 | # update all instances of class |
| 317 | update_instances(old, new) |
| 318 | |
| 319 | |
| 320 | def update_property(old, new): |
nothing calls this directly
no test coverage detected