MCPcopy Index your code
hub / github.com/python/cpython / _update_func_cell_for__class__

Function _update_func_cell_for__class__

Lib/dataclasses.py:1283–1301  ·  view source on GitHub ↗
(f, oldcls, newcls)

Source from the content-addressed store, hash-verified

1281
1282
1283def _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
1304def _create_slots(defined_fields, inherited_slots, field_names, weakref_slot):

Callers 1

_add_slotsFunction · 0.85

Calls 1

indexMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…