A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-bugs-list/2005-October/030504.html below:

[ python-Bugs-1309724 ] __getnewargs__ is in pickle docs but not in code

[ python-Bugs-1309724 ] __getnewargs__ is in pickle docs but not in codeSourceForge.net noreply at sourceforge.net
Sat Oct 1 04:57:11 CEST 2005
Bugs item #1309724, was opened at 2005-09-30 12:37
Message generated for change (Comment added) made by nnorwitz
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1309724&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.3
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Myers Carpenter (myers_carpenter)
>Assigned to: Neal Norwitz (nnorwitz)
Summary: __getnewargs__ is in pickle docs but not in code

Initial Comment:
The pickle docs talk about __getnewargs__ for new style
classes

http://www.python.org/doc/2.3.5/lib/pickle-inst.html

But after examing pickle.py I see no ref to
__getnewargs__ in the code, nor could I get my example
code to work.


----------------------------------------------------------------------

>Comment By: Neal Norwitz (nnorwitz)
Date: 2005-09-30 19:57

Message:
Logged In: YES 
user_id=33168

The code is buried in the C implementation of Objects.  In
the doc you reference, this is the relative sentance:

  New-style types can provide a __getnewargs__() method that
is used for protocol 2.

Note that last phrase about requiring protocol 2.  Your
example works if you add a third parameter to pickle.dump()
with the value of 2.  Version 2 is not default.

Hope this makes sense.

----------------------------------------------------------------------

Comment By: Myers Carpenter (myers_carpenter)
Date: 2005-09-30 14:59

Message:
Logged In: YES 
user_id=335935

Example code:

import pickle

class A(object):
    def __new__(klass, *args):
        print "__new__ %r" % (args,)
        return object.__new__(klass, *args)

    def __init__(self, *args):
        print "__init__"
        self.args = args

    def __getnewargs__(self):
        print "__getnewargs__"
        return (self.args,)

print "object creation"
a = A("a", "b",)

print "pickle dump"
pickle.dump(a, file("pickle.gnatest", "w"))

del a

print "pickle load"
a = pickle.load(file("pickle.gnatest", "r"))

print a


Output:

object creation
__new__ ('a', 'b')
__init__
pickle dump
pickle load
<__main__.A object at 0x4022096c>


Expected:
"__getnewargs__" never printed, __new__ not called after
object load.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1309724&group_id=5470
More information about the Python-bugs-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4