Consider the following code:
from enum import Enum
class A(object):
class B(object):
blah = "foo"
derp = "bar"
class SubA(object):
def __init__(self):
self.value = B.derp
This raises a NameError
>>> A.SubA()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "test.py", line 10, in __init__
self.value = B.derp
NameError: name 'B' is not defined
On the other hand, replacing B.derp with A.B.derp makes the code work as desired.
Why does Python's scoping resolve this in the way it does, and why should this make sense in Python's design?