[Python-ideas] PEP 572 version 2: Statement-Local Name Bindings
Ethan Furman
ethan at stoneleaf.us
Fri Mar 2 13:36:45 EST 2018
On 03/02/2018 08:04 AM, Chris Angelico wrote:
> On Sat, Mar 3, 2018 at 1:53 AM, Rhodri James wrote:
>> On 02/03/18 11:43, Chris Angelico wrote:
>>> # Compound statements usually enclose everything...
>>> if (re.match(...) as m):
>>> print(m.groups(0))
>>> print(m) # NameError
>>
>> This (and the equivalent in while loops) is the big win in the PEP, in my
>> opinion. The number of ugly loops I've had to write in Python because I
>> can't write "while (something_to_do() as event):"... +1 on this.
>>
>>> # Using a statement-local name
>>> stuff = [[(f(x) as y), x/y] for x in range(5)]
>>
>> As Paul said, the asymmetry of this bothers me a lot. It doesn't read
>> naturally to me. -1 on this.
>
> Interesting. I fully expected to get a lot more backlash for the
> if/while usage, but a number of people are saying that that's the only
> (or the biggest) part of this proposal that they like.
This is the part of the PEP that I really like as well -- far more useful to me than the list-comp examples. I could
even be +0.5 if the "if/while/for" compound statements were kept and the comprehensions dropped -- but not with leading
dots -- I would rather do $ than . . Kind of like decorators, they shouldn't be used all that often.
--
~Ethan~
More information about the Python-ideas
mailing list