This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: class dictionary shortcircuits __getattr__
Type: Stage:
Components: Documentation Versions: Python 2.4
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, shauncutts
Priority: normal Keywords:

Created on 2006-01-31 07:08 by shauncutts, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg27391 - (view) Author: Shaun Cutts (shauncutts) Date: 2006-01-31 07:08
page 3.3.2 of Language Reference states:

"....Note that at least for instance variables, you 
can fake total control by not inserting any values in 
the instance attribute dictionary (but instead 
inserting them in another object)."

A counterexample (doctest style):
-----------------------------
>>> class Foo:
...     bar = None
...     def __getattr__( self, attr ):
...         return 'boo'
...
>>> f = Foo()
>>> print "bar: ",f.bar
bar: None
------------------------------
'bar' in class dictionary (not just in instance 
dictionary) also causes __getattr__ not to be called.

BTW.. above in the doc, it says that __getattr__ 
called only if "normal methods" can't find attribute. 
So this would seem a documentation bug. 

However, right now at least, I would prefer if the 
instance dictionary alone were decisive.
msg27392 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-02-17 12:16
Logged In: YES 
user_id=1188172

This is correct behavior as documented. The first sentence
in the cited page is:

""" [__getattr__ is] Called when an attribute lookup has not
found the attribute in the usual places (i.e. it is not an
instance attribute nor is it found in the class tree for
self)."""

"""Note that **at least** for instance variables,"""
explicitly tells you that you can't do anything about class
variables.
History
Date User Action Args
2022-04-11 14:56:15adminsetgithub: 42851
2006-01-31 07:08:08shauncuttscreate