Skip to main content

Practice · 2 of 3

Delegating proxy with __getattr__

CHALLENGE
Difficulty: advanced+25 XP

Implement class Proxy that wraps any object passed to __init__: - attribute reads that fail on the Proxy itself must be **delegated** to the wrapped object via __getattr__ - Proxy.real(obj) must return the wrapped object - calls on delegated methods must work (e.g. Proxy('hi').upper() returns 'HI') - reads of attributes the wrapper defines directly must NOT be delegated (define sniff on Proxy returning 'proxy')

Back to lesson: Practice: Attribute Lookup Practice