Re:Chris Lattner on garbage collection vs. Automatic Referen...
by xscott on Sunday April 24, 2022 @04:07AM
(#31142135)
Python doesn't have block scope, but most people don't seem to notice:
def foo():
if False:
x = 123
print("x is visible out here:", x)
That will generate an error because `x` is "referenced before assignment", but the variable exists for the entire function. This can bite you in subtle ways: x = "is global out here"
def foo():
print("all good:", x)
def bar():
print("not good:", x)
if False:
x = "now x is local, even before this declaration"
However: