Andrew Dalke wrote: > On Feb 19, 2008 1:38 PM, Andrew Dalke <[EMAIL PROTECTED]> wrote: >> def spam((a) = c): >> print a > > On Feb 20, 2008 12:29 AM, Brett Cannon <[EMAIL PROTECTED]> wrote: [..] >> Are you asking why the decision was made to make the expression >> illegal, or why the grammar is flagging it is wrong? > > Why it's illegal. Supporting a comma doesn't seem to make anything > ambiguous, but PLY's LALR(1) might handle things that Python itself > doesn't and I don't have the experience to tell. > It's illegal, in short, because formal parameters can be names or tuples, and a parenthesized expression (albeit one containing only a single term) is neither.
You could argue that parenthesizing a name shouldn't turn it into a value, but to me there does seem to be a significant difference between a and (a) - in Algol 68 terms, the former can be dereferenced automatically while the latter cannot. It's a pretty fine hair to split, though. > There are other places where the grammar definition allows syntax that > is rejected later on. Those I can justify by saying it's easier to > define the grammar that way (hence f(1+1=2) is legal grammar but > illegal Python), or to produce better error messages (like "from .a > import *"). > > But this one prohibiting [x for x in 1,] I can't figure out. > The one that surprised me was the legality of def eggs((a, )=c): pass That just seems like unpacking-abuse to me. You might argue that c might be a singleton tuple, though that is known when the definition is processed, but there's no way you can say the same of a float. Python 2.5.1 (r251:54863, May 18 2007, 16:56:43) [GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> def eggs((a, )=2.1): ... pass ... >>> Oops. 'def eggs((a, )=(2.1, )):' I'd have gone for, but your example just seems broken. You really *have* been poking around in little-known crevices, haven't you? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com