(f, oldcls, newcls)
| 1281 | |
| 1282 | |
| 1283 | def _update_func_cell_for__class__(f, oldcls, newcls): |
| 1284 | # Returns True if we update a cell, else False. |
| 1285 | if f is None: |
| 1286 | # f will be None in the case of a property where not all of |
| 1287 | # fget, fset, and fdel are used. Nothing to do in that case. |
| 1288 | return False |
| 1289 | try: |
| 1290 | idx = f.__code__.co_freevars.index("__class__") |
| 1291 | except ValueError: |
| 1292 | # This function doesn't reference __class__, so nothing to do. |
| 1293 | return False |
| 1294 | # Fix the cell to point to the new class, if it's already pointing |
| 1295 | # at the old class. I'm not convinced that the "is oldcls" test |
| 1296 | # is needed, but other than performance can't hurt. |
| 1297 | closure = f.__closure__[idx] |
| 1298 | if closure.cell_contents is oldcls: |
| 1299 | closure.cell_contents = newcls |
| 1300 | return True |
| 1301 | return False |
| 1302 | |
| 1303 | |
| 1304 | def _create_slots(defined_fields, inherited_slots, field_names, weakref_slot): |
no test coverage detected
searching dependent graphs…