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
)
| 540 | |
| 541 | |
| 542 | def _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 | |
| 567 | def _make_skeleton_enum( |
nothing calls this directly
no test coverage detected