Author eric.snow
Recipients eric.snow
Date 2012-10-16.18:24:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1350411894.01.0.763638555345.issue16251@psf.upfronthosting.co.za>
In-reply-to
Content
In Objects/typeobject.c, reduce_2() makes _PyObject_GetAttrId() calls to pull some methods for the object in question.  This is a problem when the object's type defines __getattr__() or __getattribute__() and returns something like None when the attribute is not found:


from copy import deepcopy

class Spam(dict):
    def __getattr__(self, name):
        # defaults to None
        return self.get(name)

deepcopy(Spam(ham=5))


While we could do a check on the result of _PyObject_GetAttrId() to make sure it is callable, the better solution would be to look up the methods on the object's type rather than on the object.  Doing so falls in line with the specified pattern for special method lookup [1].  I'm guessing there are a few other related places in typeobject.c that have the same problem which could be fixed in the same way.

I'm marking this as a bug rather than a feature since it is a deviation from the specification for special methods.

[1] http://docs.python.org/dev/reference/datamodel.html#special-method-lookup
History
Date User Action Args
2012-10-16 18:24:54eric.snowsetrecipients: + eric.snow
2012-10-16 18:24:54eric.snowsetmessageid: <1350411894.01.0.763638555345.issue16251@psf.upfronthosting.co.za>
2012-10-16 18:24:53eric.snowlinkissue16251 messages
2012-10-16 18:24:53eric.snowcreate