Re: __getattribute__ and __getattr__

2005-05-31 Thread Gigi
Terry Reedy wrote:
 Gigi [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]
 
Hi,
In the Python documentation regarding __getattribute__ (more attribute
access for new style classes) it is mentioned that if __getattribute__
is defined __getattr__ will never be called (unless called explicitely).
Here is the exact citation:
 
 
 Discrepancy reported in
 
 https://sourceforge.net/tracker/?func=detailatid=105470aid=1204734group_id=5470
 
 Guido declared behavior right and doc wrong and in need of correction.
 
 Terry J. Reedy
 
 
 

Thanks for your reply. It definitely clears the issue. I'm writing an
article to Dr. Dobbs about the Python object model and I wouldn't want
to be inaccurate. I fill a little like Leibnitz :-) . It's a curious
coincidence that two separate people notice the same documentation issue
that lingere for such a long time in such a short time span.

Thanks, Gigi



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __getattribute__ and __getattr__

2005-05-31 Thread Peter Otten
Gigi wrote:

 to be inaccurate. I fill a little like Leibnitz :-) . It's a curious

It's Leibniz -- unless you're in the cookie business.

I see your post for the third time, btw. What's wrong?

Peter

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __getattribute__ and __getattr__

2005-05-30 Thread Gigi
Terry Reedy wrote:
 Gigi [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]
 
Hi,
In the Python documentation regarding __getattribute__ (more attribute
access for new style classes) it is mentioned that if __getattribute__
is defined __getattr__ will never be called (unless called explicitely).
Here is the exact citation:
 
 
 Discrepancy reported in
 
 https://sourceforge.net/tracker/?func=detailatid=105470aid=1204734group_id=5470
 
 Guido declared behavior right and doc wrong and in need of correction.
 
 Terry J. Reedy
 
 
 

Thanks for your reply. It definitely clears the issue. I'm writing an 
article to Dr. Dobbs about the Python object model and I wouldn't want 
to be inaccurate. I fill a little like Leibnitz :-) . It's a curious 
coincidence that two separate people notice the same documentation issue 
that lingere for such a long time in such a short time span.

Thanks, Gigi


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __getattribute__ and __getattr__

2005-05-30 Thread Gigi
Terry Reedy wrote:
 Gigi [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]
 
Hi,
In the Python documentation regarding __getattribute__ (more attribute
access for new style classes) it is mentioned that if __getattribute__
is defined __getattr__ will never be called (unless called explicitely).
Here is the exact citation:
 
 
 Discrepancy reported in
 
 https://sourceforge.net/tracker/?func=detailatid=105470aid=1204734group_id=5470
 
 Guido declared behavior right and doc wrong and in need of correction.
 
 Terry J. Reedy
 
 
 

Thanks for your reply. It definitely clears the issue. I'm writing an
article to Dr. Dobbs about the Python object model and I wouldn't want
to be inaccurate. I fill a little like Leibnitz :-) . It's a curious
coincidence that two separate people notice the same documentation issue
that lingere for such a long time in such a short time span.

Thanks, Gigi



-- 
http://mail.python.org/mailman/listinfo/python-list


__getattribute__ and __getattr__

2005-05-29 Thread Gigi
Hi,
In the Python documentation regarding __getattribute__ (more attribute 
access for new style classes) it is mentioned that if __getattribute__ 
is defined __getattr__ will never be called (unless called explicitely). 
Here is the exact citation:


The following methods only apply to new-style classes.

__getattribute__(   self, name)
 Called unconditionally to implement attribute accesses for 
instances of the class. If the class also defines __getattr__, it will 
never be called (unless called explicitly). This method should return 
the (computed) attribute value or raise an AttributeError exception. In 
order to avoid infinite recursion in this method, its implementation 
should always call the base class method with the same name to access 
any attributes it needs, for example, object.__getattribute__(self, 
name).


I discovered that it is not so for Python 2.3.4 on Windows at least. The 
actual behavior is that if both __getattribute__ and __getattr__ methods 
exist then __getattribute__ is called first, but if it raises 
AttributeError then the exception will be swallowed silently and 
__getattr__ will be invoked. Note that if I forward to the default 
object.__getattribute__ or if I raise the AttributeError myself the 
result is the same. My understanding of the documentation is it that the 
program should just exit with the AttributeError exception.

Here is the code:

class A(object):
 def __getattribute__(self, name):
 return object.__getattribute__(self, name)
# raise AttributeError()

 def __getattr__(self, name):
 return 42

if __name__ == '__main__':
 a = A()
 print a.x

Here is the Output:

42


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __getattribute__ and __getattr__

2005-05-29 Thread Terry Reedy

Gigi [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Hi,
 In the Python documentation regarding __getattribute__ (more attribute
 access for new style classes) it is mentioned that if __getattribute__
 is defined __getattr__ will never be called (unless called explicitely).
 Here is the exact citation:

Discrepancy reported in

https://sourceforge.net/tracker/?func=detailatid=105470aid=1204734group_id=5470

Guido declared behavior right and doc wrong and in need of correction.

Terry J. Reedy



-- 
http://mail.python.org/mailman/listinfo/python-list