News for hackers. Stuff that matters.
Re:Understanding a Python Closure Oddity by Izkata on Monday June 17, 2024 @11:15AM (#40706442)
That would make it work differently than the entire rest of the language. Python is function-scoped, not block-scoped.
Re:Understanding a Python Closure Oddity by abecedarius on Monday June 17, 2024 @04:49PM (#40710886)
That ship already sailed when Python 3 made comprehension expressions (like list comprehensions) introduce a nested scope. They're even a kind of 'for' too. (Previously, [x for x in y] would clobber any x in the same function. Fixing this meant implicit nested scopes.)

It's true that this would've been a further change (every loop entering the implicit nest, rather than entering one nest which then mutates per loop). But this design was a decision, not a necessity. JS's "for let" shows this by example.