[Python-ideas] Assignment decorators (Re: The Descriptor Protocol...)

Paul Moore p.f.moore at gmail.com
Tue Mar 8 10:13:41 CET 2011


On 8 March 2011 03:50, Raymond Hettinger <raymond.hettinger at gmail.com> wrote:
> Just for the fun of it, here's my offering:
>
>
>    a := gizmo(arg1, arg2)
>
> is equivalent to
>
>    a = gimzo(arg1, arg2, __name__='a')

This is my favourite so far. I was wondering when someone would mention :=...

>
> Advantages:
>
>  * Doesn't rewrite the order of arguments
>  * Keep the current '@' notation unambiguous
>  * Still looks like an assignment.
>  * Would give a meaningful error message if gizmo() weren't expecting a name

Good point

>  * Doesn't look like perl
>  * Doesn't twist your mind into a pretzel

Speak for yourself :-)

>  * No new keywords
>  * Easy to adapt any existing tools that need to know their own name
>  * Doesn't seem like magic or spooky action at a distance
>  * The program still looks like a Python program
>
> Disadvantage:
>
>  * I'm still not sure that the "problem" is worth solving.
>  * Between this and function annotations, it looks like Pascal is coming back.

Didn't Algol also use :=? If so, we can think of it as Algol coming
back, and add call by name as well, for bonus fun :-)

  * Also, still doesn't give any guidance as to what should be allowed
on the LHS (which is orthogonal to the syntax discussion, I know, but
still a significant sticking point for any proposal). My view is bare
names only, because if you allow anything else, the called function
ends up having to parse a string representation.

  * Actually, also add that the syntax is very (surprisingly)
restrictive. The RHS *has* to be a bare function call, near enough. So
that makes it even less like an assignment...

I understand the frustration that drives people to want a solution,
but I don't think any of the proposals so far are unambiguous enough
to qualify (even if the problem were important enough to justify new
syntax).

Paul.



More information about the Python-ideas mailing list