[Python-ideas] "Loose" descriptors

David Wilson dw+python-ideas at hmmz.org
Sun Mar 29 04:34:05 CEST 2015


On Sat, Mar 28, 2015 at 06:35:17PM -0400, James Edwards wrote:

> But my question is would it make sense to be able to do this sort of
> indirection for "loose" objects also, not just attributes of classes
> or instances?  In other words, could descriptors be extended so that
> they perform the same sort of indirection in the second example as the
> first?

FWIW you could probably experiment with this using PyPy's object spaces
feature without modifying the interpreter:

    http://pypy.readthedocs.org/en/latest/objspace-proxies.html

The 'exec' statement also indirectly supports a restrictive version of
this, by allowing dict subclasses to be provided for globals/locals.
Naturally the effect wouldn't carry over to function calls invoked by
the statement.

As a general comment, the ability to overload scope load/store seems
like an expert feature of questionable applicability. It's fun to play
with, but I'd hope to never encounter it in code intended for
maintainability.


David


More information about the Python-ideas mailing list