[Python-Dev] SyntaxError: can't assign to function call

Phillip J. Eby pje at telecommunity.com
Fri Aug 11 21:53:08 CEST 2006


At 09:40 PM 8/11/2006 +0200, Martin v. Löwis wrote:
>Michael Urman schrieb:
> > On 8/9/06, Michael Hudson <mwh at python.net> wrote:
> >> The question doesn't make sense: in Python, you assign to a name,
> >> an attribute or a subscript, and that's it.
> >
> > Just to play devil's advocate here, why not to a function call via a
> > new __setcall__?
>
>Just try specifying this one day. I'm sure a dozen readers of the list
>will rip apart the first specification you make as underspecified or
>unimplementable (hint: what is the precise syntax for the left-hand
>side? how to parse it? what is the precise parameter list?)

Actually, this isn't as hard as you're implying.  In at least the 
"compiler.ast" package, such an operation would be represented as a 
CallFunc node as the child of an Assign node.  Wrapping the call node's 
main child expression in a Getattr for __setcall__ would then effect the 
relatively simple AST transformation required.

This is because Python's grammar *already* allows arbitrary LHS 
expressions; it's just that the compiler rejects LHS nodes that aren't a 
Getattr, Subscript, or Name.

(The above should not be confused with advocacy for the feature; I'm just 
pointing out that specifying it -- or even implementing it -- isn't that 
complicated.)



More information about the Python-Dev mailing list