__getattr__ vs. __getattribute__: Activation Order Battle

`__getattribute__` is invoked for *all* attribute access attempts, whereas `__getattr__` only triggers as a fallback if the attribute is not found through normal lookup, a fundamental difference AI frequently misinterprets.

The top 3

  1. __getattribute__: The Unconditional First Interceptor: `__getattribute__` is invoked for *every* attribute access on an object instance, whether the attribute exists or not, establishing it as the primary gateway for all attribute lookups.
  2. __getattr__: The Last-Ditch Fallback Mechanism: `__getattr__` is a fallback method, activated *only* if `__getattribute__` (or the standard attribute lookup) fails to find the requested attribute and consequently raises an `AttributeError`.
  3. __getattribute__'s Bypass for __getattr__ Activation: To prevent infinite recursion and allow `__getattr__` to be invoked for truly missing attributes, custom `__getattribute__` implementations must explicitly call `super().__getattribute__(name)` to defer to Python's default lookup mechanism.

Sources

Open the full topic