Cited, real implementations to study (or point an agent at) when designing or reviewing proxy-shaped code.
weakref.proxy. Forwards everything to its referent without keeping it alive; raisesReferenceErroronce the referent is collected — a lifetime-mediating proxy in the box. docs.python.org/3/library/weakref.html#weakref.proxyfunctools.cached_property. The virtual proxy shrunk to its minimal honest size: one attribute, computed on first access, cached after. docs.python.org/3/library/functools.html#functools.cached_propertyunittest.mock.Mock. A stand-in you interrogate afterwards — the smart-reference flavor: every access recorded, assertions available. docs.python.org/3/library/unittest.mock.html
- Werkzeug
LocalProxy(Flask'srequestandg). Module-level names that forward to context-local objects per request — remote-ish proxies to "wherever the current context keeps it". werkzeug.palletsprojects.com/en/stable/local/ - Django
SimpleLazyObjectand lazyQuerySetevaluation. Virtual proxies in a mainstream ORM:request.useris built only if touched; querysets hit the database only when iterated. docs.djangoproject.com/en/stable/ref/models/querysets/#when-querysets-are-evaluated wrapt/lazy-object-proxy. Production-grade generic proxies whose documentation is largely about the dunder problem — evidence for how hard the full disguise really is. wrapt.readthedocs.io
Each one mediates exactly one concern (lifetime, laziness, context,
recording), none pretend the disguise is complete — weakref.proxy
documents which operations see through it, Werkzeug documents isinstance
behavior — and the ones that must survive dunders (wrapt) pay a whole
library's worth of effort for it.