Bugs item #1204734, was opened at 2005-05-19 05:21
Message generated for change (Settings changed) made by gbrandl
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1204734&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: Documentation
Group: None
Status: Closed
Resolution: Fixed
Priority: 5
Submitted By: John Eikenberry (zhar)
>Assigned to: Georg Brandl (gbrandl)
Summary: __getattribute__ documentation error?

Initial Comment:
>From http://www.python.org/dev/doc/devel/ref/new-style-attribute-access.html

"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)."

But I'm not seeing this behaviour in python-2.3.5 and python-2.4.1 on Linux.

class A(object):

    def __getattr__(self,key):
        print '__getattr__',key
        raise AttributeError,key

    def __getattribute__(self,key):
        print '__getattribute__',key
        raise AttributeError,key

a = A()
a.foo

$ python test.py
__getattribute__ foo
__getattr__ foo
Traceback (most recent call last):
  File "test.py", line 14, in ?
    a.foo
  File "test.py", line 7, in __getattr__
    raise AttributeError(key)
AttributeError: foo

It seems to be calling __getattribute__ as it should, but then it falls back on 
__getattr__ even though the docs specifically say it shouldn't.



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

Comment By: Georg Brandl (birkenfeld)
Date: 2005-07-02 10:30

Message:
Logged In: YES 
user_id=1188172

Checked in my patch as Doc/ref/ref3.tex r1.125, r1.121.2.4.

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

Comment By: Georg Brandl (birkenfeld)
Date: 2005-06-04 10:03

Message:
Logged In: YES 
user_id=1188172

Attached a documentation patch, following Terry's wording.

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

Comment By: Terry J. Reedy (tjreedy)
Date: 2005-05-26 17:42

Message:
Logged In: YES 
user_id=593130

If I understand correctly, this revision of the consequent of the 
second sentence (after ',') matches the implementation.

[If the class also defines __getattr__, ]
the latter will not be called unless __getattribute__ either calls it 
explicitly or raises an AttributeError.


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

Comment By: Guido van Rossum (gvanrossum)
Date: 2005-05-26 16:18

Message:
Logged In: YES 
user_id=6380

The implementation works as expected.

The documentation is flawed.

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

Comment By: John Eikenberry (zhar)
Date: 2005-05-26 15:52

Message:
Logged In: YES 
user_id=322022

Terry, I started with a much longer subject but decided I
didn't want to overload it to much. Guess I went to far the
other way. I'll try to strike a better balance next time.

Thanks.

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

Comment By: Terry J. Reedy (tjreedy)
Date: 2005-05-26 15:43

Message:
Logged In: YES 
user_id=593130

John E: A general title like 'Documentation Error?' discourages 
attention from people with the specialized knowledge needed to 
answer such a question.  I have taken the liberty of trying to 
add '__getattribute__'.  We'll see if the edit works when I, not the 
OP, submits it.

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

Comment By: Terry J. Reedy (tjreedy)
Date: 2005-05-26 15:33

Message:
Logged In: YES 
user_id=593130

If the default __getattribute__ explicitly calls __getattr__ (but I 
don't know which source file to check), then the second 
sentence above *would* make some sense.

Guido (or deputy): what is your design intention?

Note: if the second sentence is kept, replacing 'it' with 'the latter' 
would make it clearer. I first read 'it' as referring to 
__getattribute__.

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

Comment By: Armin Rigo (arigo)
Date: 2005-05-24 09:08

Message:
Logged In: YES 
user_id=4771

I'll wait for an "authorized" confirmation, but so far I think that the current 
implementation is really how it is supposed to work.  The method 
'object.__getattribute__' must be there, given that it is a common technique to 
use it directly in overridden __getattribute__ implementations.  As a 
consequence, __getattribute__ cannot completely shadow __getattr__, or 
__getattr__ would never be called.

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

Comment By: John Eikenberry (zhar)
Date: 2005-05-23 18:43

Message:
Logged In: YES 
user_id=322022

Please specify in the documentation whether this is how it
is supposed to work or whether this is a side-effect of the
implementation. To make explicit if you can write code
relying on this 'feature' and not have it break at some point.

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

Comment By: Armin Rigo (arigo)
Date: 2005-05-23 14:28

Message:
Logged In: YES 
user_id=4771

Indeed, the logic in typeobject.c is to call __getattribute__ and fall back on 
__getattr__ if the former raised an AttributeError.  This is necessary because 
all objects have a __getattribute__, actually, as there is one in the 'object' 
base class.  This let me think that the error is really in the documentation, 
which should mention this logic.

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

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1204734&group_id=5470
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to