<div class="gmail_quote">On Mon, Mar 7, 2011 at 4:56 PM, Larry Hastings <span dir="ltr"><<a href="mailto:larry@hastings.org">larry@hastings.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im"><br>
On 03/03/2011 03:45 PM, Greg Ewing wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I think we should have assignment decorators.<br>
<br>
@decorator<br>
lhs = rhs<br>
<br>
would be equivalent to<br>
<br>
lhs = decorator('lhs', rhs)<br>
<br>
</blockquote>
<br></div>
I timidly propose an alternate syntax. What I don't like about the above proposal: assignment is no longer a one-liner. So let's try it inline.<br>
<br>
Example 1:<br>
<br>
lhs = @decorator<br>
<br>
is equivalent to<br>
<br>
lhs = decorator(classobject, 'lhs', None)<br>
<br>
<br>
Example 2:<br>
<br>
lhs = @dec1 @dec2<br>
<br>
is equivalent to<br>
<br>
lhs = dec2(classobject, 'lhs', dec1(classobject, 'lhs', None))<br>
<br>
<br>
Example 3:<br>
<br>
lhs = @dec1('string', 3.14)<br>
<br>
is equivalent to<br>
<br>
lhs = dec1('string', 3.14)(classobject, 'lhs', None)<br></blockquote><div><br></div><div>You seemed to have missed the example of:</div><div><br></div><div>lhs = @dec1 123</div><div><br></div><div>which would produce</div>
<div><br></div><div>dec1(classobject, 'lhs', 123)</div><div><br></div><div>correct?</div><div><br></div><div>If so, the separation between dec1 and 123 seems too little - it looks like typos like:</div><div>lhs = @dec1123</div>
<div>lhs = @dec123</div><div><br></div><div>would be easy to make and difficult to detect.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
(Here you are presumed to return a callable closure with the default values baked in.)<br>
<br>
Outside class scope, classobject is None. I think you want the classobject there so you can cache information in it, like using the variable declarations to build up a per-class database schema.<br>
<br>
<br>
I'm not confident any of this is a good idea; luckily this isn't the python-good-ideas-only list. Phew!<br><font color="#888888">
<br>
<br>
/larry/</font><div><div></div><div class="h5"><br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/mailman/listinfo/python-ideas</a><br>
</div></div></blockquote></div><br>