I'm aware that the methods __getattribute__
and __getattr__
do not do the same thing; the former is responsible for all attribute access and the latter, if defined, is called when the former raises AttributeError.
What puzzles me is why two similarly named methods related to attribute access even exist for a language that usually tries to eliminate confusion. I can't even think of a situation where I would HAVE to define a __getattr__
; I can just define a __getattribute__
that uses object.__getattribute__
in an if statement or try statement. Moreover, the built-in function for attribute access is named getattr
which would mislead people into thinking __getattr__
is the go-to method for attribute access. What's the history behind these two methods and is there a good reason they both still exist?