On 25 March 2018 at 17:18, Chris Angelico firstname.lastname@example.org wrote:
Agreed. I'm currently thinking that I need to do what several people have suggested and break this into two completely separate PEPs:
- Sublocal namespacing
- Assignment expressions
Sublocal names can be used in a number of ways. There could be a "with sublocal EXPR as NAME:" syntax that actually disposes of the name binding at the end of the block,
The scoping affects the name binding rather than the expression evaluation, so I'd expect any such variant to be:
with EXPR as sublocal NAME: ...
and "except Exception as e:" could shadow rather than unbinding. Maybe list comprehensions could change, too - instead of creating a function, they just create a sublocal scope.
That may be the best way forward. I'm not sure.
I think you can treat it as an open design question within the current PEP by tweaking the PEP title to be "Name binding as an expression".
If we allow expression level name binding at all, it will be an either/or choice between binding to a new sublocal scope and binding regular locals, and you can handle that by describing sublocals as your current preferred option, but point out that the same *syntactic* idea could be adopted without introducing the sublocals semantics (in the latter case, the distinction created by the PEP would just be between "assignment statements" and "assignment expressions", rather than between "local assignments" and "sublocal assignments").