On Tue, May 25, 2021 at 5:29 PM Steven D'Aprano <firstname.lastname@example.org> wrote:
> Here's a counter-proposal: we have a special symbol which is transformed
> at compile-time to the left hand assignment target as a string. Let's
> say we make that special expression `@@` or the googly-eyes symbol.
1) Is this restricted to the "=" assignment operator, or will other
operators trigger this too?
x += f(@@) # ?
if x := f(@@): # ?
2) What about other forms of assignment?
for spam in foo(@@): # ?
with open(@@ + ".json") as config: # ?
from sys import @@ as argv # okay that's just stupid
3) Is this a string literal, or a magic token that happens to evaluate
as a string?
x = @@ ".json" # Legal if @@ is a string literal
No wrong answers. (Well, unless you say "tomato". That is a very wrong
answer to a yes/no question.)
I'm liking this. It might mean that class syntax and decorator abuse
become less necessary as ways to get around name duplication.