[Python-ideas] PEP 572: Statement-Local Name Bindings

Chris Angelico rosuav at gmail.com
Wed Feb 28 14:45:16 EST 2018


On Thu, Mar 1, 2018 at 5:03 AM, Kirill Balunov <kirillbalunov at gmail.com> wrote:
>
> The PEP says:
>
>>
>> Omitting the parentheses from this PEP's proposed syntax introduces many
>> syntactic ambiguities.
>
>
> and:
>
>> As the name's scope extends to the full current statement, even a block
>> statement, this can be used to good effect in the header of an if or while
>> statement
>
>
>
> Will the `from ... import ... as ... statement be a special case, because
> currently the following form is valid:
>
> from math import (tau as two_pi)

No, because that statement doesn't have any expressions in it - it's a
series of names. The "tau" in that line is not looked up in the
current scope; you can't write a function that returns the symbol
"tau" and then use that in the import. So the grammatical hook that
enables "(... as ...)" doesn't apply here.

ChrisA


More information about the Python-ideas mailing list