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

Function _make_skeleton_class

cloudpickle/cloudpickle.py:542–564  ·  view source on GitHub ↗

Build dynamic class with an empty __dict__ to be filled once memoized If class_tracker_id is not None, try to lookup an existing class definition matching that id. If none is found, track a newly reconstructed class definition under that id so that other instances stemming from the same

(
    type_constructor, name, bases, type_kwargs, class_tracker_id, extra
)

Source from the content-addressed store, hash-verified

540
541
542def _make_skeleton_class(
543 type_constructor, name, bases, type_kwargs, class_tracker_id, extra
544):
545 """Build dynamic class with an empty __dict__ to be filled once memoized
546
547 If class_tracker_id is not None, try to lookup an existing class definition
548 matching that id. If none is found, track a newly reconstructed class
549 definition under that id so that other instances stemming from the same
550 class id will also reuse this class definition.
551
552 The "extra" variable is meant to be a dict (or None) that can be used for
553 forward compatibility shall the need arise.
554 """
555 # We need to intern the keys of the type_kwargs dict to avoid having
556 # different pickles for the same dynamic class depending on whether it was
557 # dynamically created or reconstructed from a pickled stream.
558 type_kwargs = {sys.intern(k): v for k, v in type_kwargs.items()}
559
560 skeleton_class = types.new_class(
561 name, bases, {"metaclass": type_constructor}, lambda ns: ns.update(type_kwargs)
562 )
563
564 return _lookup_class_or_track(class_tracker_id, skeleton_class)
565
566
567def _make_skeleton_enum(

Callers

nothing calls this directly

Calls 1

_lookup_class_or_trackFunction · 0.85

Tested by

no test coverage detected