
On 5/18/2019 10:01 PM, Chris Angelico wrote:
2) Redefine the 'with' block or create a new syntactic form such that the variable actually creates a subscope. That way, at the end of the block, the name would revert to its former meaning.
x = 1 with local 2 as x: print(x) # 2 print(x) # 1
Since Python allows both multiple character names and unicode names, there is no shortage of names, and hence hardly any need for such temporary rebinding. Function and class bodies must be sub-scoped each for their own reasons.
This would have definite value,
Not much. If one wants to explicitly localize the use of (new) names, one can explicitly delete them. x1 = 1 ... x2, x3 = 2, 3 h = hypot(x2, x3) del x2, x3 # Okay reader, you can forget about x2, x3. ... print(1) -- Terry Jan Reedy