MCPcopy Create free account
hub / github.com/cloudpipe/cloudpickle / _extract_class_dict

Function _extract_class_dict

cloudpickle/cloudpickle.py:426–448  ·  view source on GitHub ↗

Retrieve a copy of the dict of a class without the inherited method.

(cls)

Source from the content-addressed store, hash-verified

424
425
426def _extract_class_dict(cls):
427 """Retrieve a copy of the dict of a class without the inherited method."""
428 # Hack to circumvent non-predictable memoization caused by string interning.
429 # See the inline comment in _class_setstate for details.
430 clsdict = {"".join(k): cls.__dict__[k] for k in sorted(cls.__dict__)}
431
432 if len(cls.__bases__) == 1:
433 inherited_dict = cls.__bases__[0].__dict__
434 else:
435 inherited_dict = {}
436 for base in reversed(cls.__bases__):
437 inherited_dict.update(base.__dict__)
438 to_remove = []
439 for name, value in clsdict.items():
440 try:
441 base_value = inherited_dict[name]
442 if value is base_value:
443 to_remove.append(name)
444 except KeyError:
445 pass
446 for name in to_remove:
447 clsdict.pop(name)
448 return clsdict
449
450
451def is_tornado_coroutine(func):

Callers 2

test_extract_class_dictFunction · 0.90
_class_getstateFunction · 0.85

Calls 1

joinMethod · 0.80

Tested by 1

test_extract_class_dictFunction · 0.72