This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author christian.heimes
Recipients christian.heimes, georg.brandl
Date 2008-09-09.12:13:12
SpamBayes Score 1.5087808e-06
Marked as misclassified No
Message-id <1220962394.03.0.479554047795.issue3816@psf.upfronthosting.co.za>
In-reply-to
Content
The pickle system has an undocumented but very useful feature. When the
first element of the tuple returned by __reduce__ is a function named
__newobj__, a special obcode is generated. __newobj__ doesn't need to be
registered as safe for unpickling, too.

From pickle.py:

            # use the more efficient NEWOBJ opcode, while still
            # allowing protocol 0 and 1 to work normally.  For this to
            # work, the function returned by __reduce__ should be
            # called __newobj__, and its first argument should be a
            # new-style class.  The implementation for __newobj__
            # should be as follows, although pickle has no way to
            # verify this:
            #
            # def __newobj__(cls, *args):
            #     return cls.__new__(cls, *args)
            #
            # Protocols 0 and 1 will pickle a reference to __newobj__,
            # while protocol 2 (and above) will pickle a reference to
            # cls, the remaining args tuple, and the NEWOBJ code,
            # which calls cls.__new__(cls, *args) at unpickling time
            # (see load_newobj below).  If __reduce__ returns a
            # three-tuple, the state from the third tuple item will be
            # pickled regardless of the protocol, calling __setstate__
            # at unpickling time (see load_build below).
            #
            # Note that no standard __newobj__ implementation exists;
            # you have to provide your own.  This is to enforce
            # compatibility with Python 2.2 (pickles written using
            # protocol 0 or 1 in Python 2.3 should be unpicklable by
            # Python 2.2).
History
Date User Action Args
2008-09-09 12:13:14christian.heimessetrecipients: + christian.heimes, georg.brandl
2008-09-09 12:13:14christian.heimessetmessageid: <1220962394.03.0.479554047795.issue3816@psf.upfronthosting.co.za>
2008-09-09 12:13:13christian.heimeslinkissue3816 messages
2008-09-09 12:13:12christian.heimescreate