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)
| 269 | |
| 270 | |
| 271 | def update_instances(old, new): |
| 272 | """Use garbage collector to find all instances that refer to the old |
| 273 | class definition and update their __class__ to point to the new class |
| 274 | definition""" |
| 275 | |
| 276 | refs = gc.get_referrers(old) |
| 277 | |
| 278 | for ref in refs: |
| 279 | if type(ref) is old: |
| 280 | ref.__class__ = new |
| 281 | |
| 282 | |
| 283 | def update_class(old, new): |