I actually encountered this for the first time yesterday and didn&#39;t realise that the decorator syntax was limited in this way (I was mentally preparing a blog entry when these emails arrived).<br><br>What I needed to do was turn a Python function  into a .NET event handler in IronPython. The simple case is this:<br>
<br>from System import EventHandler<br><br>@EventHandler<br>def on_event(sender, event):<br>    # do stuff...<br><br>This works fine of course, but then I needed to use the &#39;typed&#39; form which is like this:<br><br>
@EventHandler[HtmlEventArgs]<br>def on_event(sender, event):<br>    # do stuff...<br><br>I didn&#39;t realise this was invalid syntax - nor the neat trick with the identity function to bypass the limitation.<br><br>Michael<br>
<br><div class="gmail_quote">2009/9/2 Carl Johnson <span dir="ltr">&lt;<a href="mailto:cmjohnson.mailinglist@gmail.com">cmjohnson.mailinglist@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Crossposting to Python-ideas,<br>
<br>
I asked for the same change to the grammar a couple months back on<br>
python-ideas.<br>
<br>
See <a href="http://mail.python.org/pipermail/python-ideas/2009-February/thread.html#2787" target="_blank">http://mail.python.org/pipermail/python-ideas/2009-February/thread.html#2787</a><br>
<br>
I&#39;m all for it, but you&#39;ll have to convince Guido that this won&#39;t<br>
result in confusing to read code. My own examples, unfortunately did<br>
not advance your cause, as Guido explained, &quot;My brain hurts trying to<br>
understand all this. I don&#39;t think this bodes well as a use case for a<br>
proposed feature.&quot; :-D The trouble is that I was using lambdas upon<br>
lambdas to do all kinds of Ruby block-esque tricks. OTOH, if you come<br>
up with some simple, clear use cases though, and I think he might<br>
still be persuadable to make a simple change to the grammar.<br>
<br>
<br>
— Carl Johnson<br>
<div><div></div><div class="h5"><br>
Rob Cliffe &lt;<a href="mailto:rob.cliffe@btinternet.com">rob.cliffe@btinternet.com</a>&gt; wrote:<br>
<br>
&gt; Hi All,<br>
&gt; This is my first post to python-dev so I will briefly introduce myself:  My<br>
&gt; name is Rob Cliffe and I am a commercial programmer living in London, UK.  I<br>
&gt; have some 30 years of programming experience but have only been using Python<br>
&gt; for a couple of years.<br>
&gt; First I want to say what a fantastic language Python is.  It is THE best<br>
&gt; language for development in my opinion, and a joy to use.<br>
&gt;<br>
&gt; My specific issue:<br>
&gt; I eventually got my head round decorator syntax and realised that what came<br>
&gt; after the &#39;@&#39; was (basically) a function that took a function as argument<br>
&gt; and returned a function as result.<br>
&gt; However it seems to me unPythonesque (i.e. an exception to Python&#39;s normal<br>
&gt; consistency) that the syntax of what follows the &#39;@&#39; should be restricted to<br>
&gt; either a single (function) identifier or a single (function) identifier with<br>
&gt; an argument list.<br>
&gt; The example I tried, which seems not an unreasonable sort of thing to do,<br>
&gt; was along the lines of:<br>
&gt;<br>
&gt; def deco1(func):<br>
&gt;     &lt;deco1-suite&gt;<br>
&gt; def deco2(func):<br>
&gt;     &lt;deco2-suite&gt;<br>
&gt;<br>
&gt; DecoList = [deco1, deco2]<br>
&gt;<br>
&gt; @DecoList[0]    # NO - CAUSES SYNTAX ERROR<br>
&gt; def foo():<br>
&gt;     pass<br>
&gt;<br>
&gt; I am sure other guys have their own examples.<br>
&gt;<br>
&gt; I am of course not the first person to raise this issue, and I see that<br>
&gt; Guido has a &quot;gut feeling&quot; against allowing a general expression after the<br>
&gt; &#39;@&#39;.<br>
&gt;<br>
&gt; BUT - a general expression can be &quot;smuggled in&quot; very easily as a function<br>
&gt; argument:<br>
&gt;<br>
&gt; def Identity(x): return x<br>
&gt;<br>
&gt; @Identity(DecoList[0])    # THIS WORKS<br>
&gt; def foo():<br>
&gt;     pass<br>
&gt;<br>
&gt; So - the syntax restriction seems not only inconsistent, but pointless; it<br>
&gt; doesn&#39;t forbid anything, but merely means we have to do it in a slightly<br>
&gt; convoluted (unPythonesque) way.  So please, Guido, will you reconsider?<br>
&gt;<br>
&gt; Best wishes<br>
&gt; Rob Cliffe<br>
</div></div>_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">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>
</blockquote></div><br><br clear="all"><br>-- <br><a href="http://www.ironpythoninaction.com/">http://www.ironpythoninaction.com/</a><br><br><br>