Message5410

Author iamedu
Recipients iamedu
Date 2010-01-06.13:19:10
SpamBayes Score 2.0658367e-08
Marked as misclassified No
Message-id <1262783952.08.0.594813559384.issue1534@psf.upfronthosting.co.za>
In-reply-to
Content
This is a bit strange, here is the sample:

class Attr(object):
    def __init__(self, name):
        self.name = name

    def __set__(self, instance, value):
        instance.__dict__[self.name] = value


class Test(object):
    attr = Attr('attr')

    def test(self):
        self.attr = 5

t = Test()
print t.attr
t.test()
print t.attr

In python, if you have a newstyle object called x, and in some point define the attribute __dict__["x"] as 5 then getting the value of x. So in python that program would return:

<__main__.Attr object at 0x7f1b820b7f90>
5

On jython it returns:

<__main__.Attr object at 0x1>
<__main__.Attr object at 0x1>

A workaround would be to add a __get__ method something like this:

    def __get__(self, instance, owner):
        return instance.__dict__[self.name]

But for compatibility it would be nice to change this.

Thanks!
History
Date User Action Args
2010-01-06 13:19:12iamedusetrecipients: + iamedu
2010-01-06 13:19:12iamedusetmessageid: <1262783952.08.0.594813559384.issue1534@psf.upfronthosting.co.za>
2010-01-06 13:19:11iamedulinkissue1534 messages
2010-01-06 13:19:10iameducreate