[Python-ideas] Allowing def to assign to anything
Andrew Barnert
abarnert at yahoo.com
Mon Oct 26 02:19:43 EDT 2015
On Oct 25, 2015, at 23:02, Alexander Walters <tritium-list at sdamon.com> wrote:
>
> In my code, I write a lot of dispatch dictionaries (for lack of a switch statement, but I will not hold my breath for that). In trying to make writing these dictionaries less annoying, I tend to use many lambdas. I can let you guess at what problems that has resulted in. Of course, the preferred way to write such dictionaries is by using a regular function, and adding that function to a dictionary. This isn't exactly a problem - it works, and works well, but it is annoying to write, and leaves artifacts of those functions in module scope. I propose a little bit of sugar to make this a little less annoying.
>
> If `def` is allowed to assign to anything (anything that is legal at the left hand side of an = in that scope), annoying artifacts go away. The syntax I propose should be backwards compatible.
Seems interesting.
What's the name of the defined function? For an attribution like "spam.eggs" you'd probably want it to be "eggs", and I guess for "spam['eggs']" as well, but what about "spam['two words']" or "spam[2]"?
I assume the qualname is just the name.
Also, would this go through the descriptor mechanism if you def an attribution?
More information about the Python-ideas
mailing list