diff options
| author | Guido van Rossum <guido@python.org> | 2003-01-31 17:17:49 (GMT) | 
|---|---|---|
| committer | Guido van Rossum <guido@python.org> | 2003-01-31 17:17:49 (GMT) | 
| commit | f7f4517faeec7a37f5ad545092252a55e0450e10 (patch) | |
| tree | e021afc066aef9d8e14beb0899b8063b2eac92d5 /Lib/pickle.py | |
| parent | d053b4b41663b3ebf5795790e390e1dab96f2d58 (diff) | |
| download | cpython-f7f4517faeec7a37f5ad545092252a55e0450e10.zip cpython-f7f4517faeec7a37f5ad545092252a55e0450e10.tar.gz cpython-f7f4517faeec7a37f5ad545092252a55e0450e10.tar.bz2  | |
Pass the object to save_reduce(), so the memoize() call can go into
save_reduce(), before the state is pickled.  This makes it possible
for an object to be referenced from its own (mutable) state.
Diffstat (limited to 'Lib/pickle.py')
| -rw-r--r-- | Lib/pickle.py | 11 | 
1 files changed, 8 insertions, 3 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py index bb840c9..ec19e24 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -329,8 +329,7 @@ class Pickler:                                  "exactly two or three elements" % reduce)          # Save the reduce() output and finally memoize the object -        self.save_reduce(func, args, state) -        self.memoize(obj) +        self.save_reduce(func, args, state, obj)      def persistent_id(self, obj):          # This exists so a subclass can override it @@ -344,7 +343,7 @@ class Pickler:          else:              self.write(PERSID + str(pid) + '\n') -    def save_reduce(self, func, args, state=None): +    def save_reduce(self, func, args, state=None, obj=None):          # This API is be called by some subclasses          # Assert that args is a tuple or None @@ -397,6 +396,9 @@ class Pickler:              if not hasattr(cls, "__new__"):                  raise PicklingError(                      "args[0] from __newobj__ args has no __new__") +            if obj is not None and cls is not obj.__class__: +                raise PicklingError( +                    "args[0] from __newobj__ args has the wrong class")              args = args[1:]              save(cls)              save(args) @@ -406,6 +408,9 @@ class Pickler:              save(args)              write(REDUCE) +        if obj is not None: +            self.memoize(obj) +          if state is not None:              save(state)              write(BUILD)  | 
