[Python-Dev] PEP 572: Assignment Expressions (original) (raw)

Chris Angelico rosuav at gmail.com
Wed Apr 18 17:03:13 EDT 2018


On Thu, Apr 19, 2018 at 6:26 AM, Barry Warsaw <barry at python.org> wrote:

On Apr 18, 2018, at 11:17, Chris Angelico <rosuav at gmail.com> wrote:

At the moment, it isn't aware of 'del’. I don’t know if it’s relevant to the current discussion, but don’t forget about implicit dels: def foo(): x = 1 try: 1/0 except ZeroDivisionError as x: pass print(x) This is one of my favorite Python oddities because it always makes me look like a genius when I diagnose it. :)

Heh, yeah. My intention is to ignore that altogether. The general policy in Python is "if ever it MIGHT be assigned to, it belongs to that scope" (so even "if 0: x = 1" will mark x as local), so sticking to that would mean treating x as local regardless of the try/except.

(On an unrelated subject, I'm keeping the "sublocal scope" concept from the original PEP on ice. It might be worth implementing exception name binding with a sublocal name. But that's for a completely separate PEP.)

ChrisA



More information about the Python-Dev mailing list