Use garbage collector to find all instances that refer to the old class definition and update their __class__ to point to the new class definition
(old, new)
| 366 | |
| 367 | |
| 368 | def update_instances(old, new): |
| 369 | """Use garbage collector to find all instances that refer to the old |
| 370 | class definition and update their __class__ to point to the new class |
| 371 | definition""" |
| 372 | |
| 373 | refs = gc.get_referrers(old) |
| 374 | |
| 375 | for ref in refs: |
| 376 | if type(ref) is old: |
| 377 | object.__setattr__(ref, "__class__", new) |
| 378 | |
| 379 | |
| 380 | def update_class(old, new): |
no test coverage detected
searching dependent graphs…