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

Method save

Lib/pickle.py:562–634  ·  view source on GitHub ↗
(self, obj, save_persistent_id=True)

Source from the content-addressed store, hash-verified

560 return GET + repr(i).encode("ascii") + b'\n'
561
562 def save(self, obj, save_persistent_id=True):
563 self.framer.commit_frame()
564
565 # Check for persistent id (defined by a subclass)
566 if save_persistent_id:
567 pid = self.persistent_id(obj)
568 if pid is not None:
569 self.save_pers(pid)
570 return
571
572 # Check the memo
573 x = self.memo.get(id(obj))
574 if x is not None:
575 self.write(self.get(x[0]))
576 return
577
578 rv = NotImplemented
579 reduce = getattr(self, "reducer_override", _NoValue)
580 if reduce is not _NoValue:
581 rv = reduce(obj)
582
583 if rv is NotImplemented:
584 # Check the type dispatch table
585 t = type(obj)
586 f = self.dispatch.get(t)
587 if f is not None:
588 f(self, obj) # Call unbound method with explicit self
589 return
590
591 # Check private dispatch table if any, or else
592 # copyreg.dispatch_table
593 reduce = getattr(self, 'dispatch_table', dispatch_table).get(t, _NoValue)
594 if reduce is not _NoValue:
595 rv = reduce(obj)
596 else:
597 # Check for a class with a custom metaclass; treat as regular
598 # class
599 if issubclass(t, type):
600 self.save_global(obj)
601 return
602
603 # Check for a __reduce_ex__ method, fall back to __reduce__
604 reduce = getattr(obj, "__reduce_ex__", _NoValue)
605 if reduce is not _NoValue:
606 rv = reduce(self.proto)
607 else:
608 reduce = getattr(obj, "__reduce__", _NoValue)
609 if reduce is not _NoValue:
610 rv = reduce()
611 else:
612 raise PicklingError(f"Can't pickle {_T(t)} object")
613
614 # Check for string returned by reduce(), meaning "save as global"
615 if isinstance(rv, str):
616 self.save_global(obj, rv)
617 return
618
619 try:

Callers 3

dumpMethod · 0.95
save_persMethod · 0.95
save_globalMethod · 0.95

Calls 12

persistent_idMethod · 0.95
save_persMethod · 0.95
getMethod · 0.95
save_globalMethod · 0.95
save_reduceMethod · 0.95
idFunction · 0.85
reduceFunction · 0.85
PicklingErrorClass · 0.85
_TFunction · 0.85
commit_frameMethod · 0.80
fFunction · 0.70
writeMethod · 0.45

Tested by

no test coverage detected