Permalink
Browse files

[1.5.x] Properly support pickling of LazyObjects in Python 3.3

Backport of 836cd26d7f3394452f1f5196eb26c99fef128a1a from master
  • Loading branch information...
clelland authored and spookylukey committed Sep 28, 2012
1 parent 3deed32 commit b430e1db5f26d1de3a5cd0d6eae18603070fdab4
Showing with 10 additions and 0 deletions.
  1. +10 −0 django/utils/functional.py
View
@@ -293,6 +293,16 @@ def __getstate__(self):
self._setup()
return self._wrapped.__dict__
# Python 3.3 will call __reduce__ when pickling; these methods are needed
# to serialize and deserialize correctly. They are not called in earlier
# versions of Python.
@classmethod
def __newobj__(cls, *args):
return cls.__new__(cls, *args)
def __reduce__(self):
return (self.__newobj__, (self.__class__,), self.__getstate__())
# Need to pretend to be the wrapped class, for the sake of objects that care
# about this (especially in equality tests)
__class__ = property(new_method_proxy(operator.attrgetter("__class__")))

0 comments on commit b430e1d

Please sign in to comment.