Getattr or Getattribute?

Talk it through out loud with your AI coach.

The problem

  • hard
  • Pro

You're writing a wrapper class that forwards any attribute it doesn't define to the object it wraps, and logs each forwarded access. Explain the difference between the getattr and getattribute special methods, which one you'd use here, and the traps to avoid.

What a strong answer covers

  • When each of the two hooks is called.
  • Which suits forwarding missing attributes, and why.
  • The recursion trap and how to avoid it.
  • Why operators and built-in functions don't go through either hook.

Common mistake: Using getattribute for simple forwarding, which intercepts everything and makes infinite recursion easy.

Knowing this is half of it. Saying it clearly out loud is the part the coach helps you practise.

Practise it out loud