Instance vs Class variable oddity
On Sat, May 18, 2019 at 1:51 PM <jfong at ms4.hinet.net> wrote:
> Correct me if I am wrong, please.
> I always think that the LEGB rule (e.g. the namespace to look up for) was applied at compile-time, only the binding was resolved "dynamically" at run-time. For example:
> def foo():
> foo() will cause a NameError. But after
> x = 5
> foo() will run correctly.
This is correct; however, this function will fail with UnboundLocalError:
x = 1
x = 2
Function locals ARE locked in at compile time.