Please consider the following short Python 2.x script:
#!/usr/bin/env python
class A(object):
class B(object):
class C(object):
pass
def __init__(self):
self.c = A.B.C()
def __init__(self):
self.b = A.B()
def main():
a = A()
print "%s: %r" % (type(a).__name__, type(a))
print "%s: %r" % (type(a.b).__name__, type(a.b))
print "%s: %r" % (type(a.b.c).__name__, type(a.b.c))
if __name__ == "__main__":
main()
The output of which, when run in Python 2.7.6, is:
A: <class '__main__.A'>
B: <class '__main__.B'>
C: <class '__main__.C'>
I was expecting a different output here. Something more along the lines of:
A: <class '__main__.A'>
A.B: <class '__main__.A.B'>
A.B.C: <class '__main__.A.B.C'>
In particular I expected to see the same qualified name that I have to give to instantiate A.B and A.B.C classes respectively.
Could anyone shed any light on why those new type classes identify themselves as rooted in __main__ instead of how they were nested in the code?
Also: is there a way to fix this by naming the nested classes explicitly, such that they will identify themselves as A.B and A.B.C respectively (or possibly in the type representation as __main__.A.B and __main__.A.B.C respectively)?