I ran into this old blog post : https://blog.kevmod.com/2014/06/
X = 0
Y = 0
def wrapper():
X = 1
Y = 1
class C(object):
print X, Y # <- what happens at this line?
X = 2
wrapper()
Apparently this prints "0,1"
!!!!
While there was a pretty thorough explanation as to why it prints it:
"The technical details are that there are a number of different opcodes that Python can use to look up names; in a function scope locals are looked up with LOAD_FAST, but in a classdef they are looked up with LOAD_NAME, which does not check any parent scopes and just skips to the global scope. Non-locals in classdefs are looked up with either LOAD_NAME or LOAD_DEREF, the latter of which will check enclosing scopes."
What I didn't understand is why it prints at all? How is printing inside a declaration even valid?