Anonymous attribute/property possible?
Michael Hudson
mwh at python.net
Mon Mar 11 05:46:13 EST 2002
bokr at oz.net (Bengt Richter) writes:
> A class with an anonymous attribute/property would provide a place to put
> get/set/del-triggered code.
>
> Use of an object with an anonymous property in an expression
> or statement would result in calling the get/set methods defined.
>
> Thus you could write foo(bar) with the effect of foo(bar.__anonymous__)
> and bar() with the effect of bar.__anonymous__()
>
> And bar = baz with the effect of bar.__anonymous__ = baz.
>
> But since __anonymous__ could be a property, you could define
> methods at will (e.g., get_bar, and set_bar) and write
> bar = baz with the effect bar.set_bar(baz) and
> foo(bar) with the effect foo(bar.get_bar())
>
> This might work nicely with an interpolated-string class.
> E.g.,
> is = IS('The get_is anonymous property method will interpolate $variables')
> print is # the reference would trigger interpolation with current values
> # you could do this now, but you'd have to write "print is.some_property"
>
Ouch.
> If you wanted to access the actual object that had an anonymous
> property, you'd have to give it a named method returning self for
> that purpose.
>
> I think this could open up a whole world of scary delights ;-)
> (And ISTM without a backwards compatibility problem).
Just in case the fact that this is a horrible idea doesn't put you off
<wink>, how would you implement this without a fairly huge performance
hit? LOAD_FAST is currently, well, fast.
Cheers,
M.
--
While preceding your entrance with a grenade is a good tactic in
Quake, it can lead to problems if attempted at work. -- C Hacking
-- http://home.xnet.com/~raven/Sysadmin/ASR.Quotes.html
More information about the Python-list
mailing list