On Sun, Apr 19, 2020 at 1:04 AM Steven D'Aprano <st...@pearwood.info> wrote:
> And one final example:
>
>     class C:
>         def method(self):
>             pass
>
> versus:
>
>     def method(self):
>         pass
>
>     class C:
>         method
>

Indeed. However, if you put "method = method", it would actually work
(modulo __qualname__ and no-arg super, I think). This is an important
distinction: are you attempting to compose syntactic symbols, or
self-contained expressions? Programming languages have infinite power
but finite complexity precisely because you can compose expressions.

Alex referred to refactoring "text that looks like an expression", and
on that point, I absolutely agree with Steven here: there are MANY
places where "text that looks like an expression" can have vastly
different meanings in different contexts. But if it actually truly is
an expression in both contexts, then it usually will have the same
meaning. (That meaning might be coloured by its context - eg name
lookups depend on where you put the code - but the meaning is still
"look up this name".) And even when it isn't always an expression, the
meanings are often closely related - the expression "spam[ham]" and
the statement "spam[ham] = 1" are counterparts.

So I think that the false parallel here IS a strike against the proposal.

>     f(**{u, v})
>
>     x = {u, v}
>     f(**x)

Logically, inside the argument list, you have a comma-separated list
of expressions. Aside from needing to parenthesize tuples, I'm pretty
sure any expression will be valid. And if you put "**" followed by an
expression, that means "evaluate this expression and then unpack the
result into the args".

Yes, I know there are some oddities ('with' statements and parentheses
come to mind). But those oddities are friction points for everyone who
runs into them, they're inconsistencies, they're nuisances. Not
something to seek more of.

(Side point: Is class scope the only place in Python where you would
logically want to write "method = method" as a statement? It's also
legal and meaningful at top-level, and has the equivalent effect of
importing a built-in into the current namespace, but I've never
actually had the need to do that.)

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/PNOCCKNPIQGYIDZZXSZTWK5VIHWBE4HN/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to