Names in the namespace are unique, but this has nothing to do with your situation here. Basically there are two different things: "names" and __name__ s. "Name" is a variable in the namespace. A __name__ is just an attribute of a class whose value is "what the class calls itself."
MyClass code above has the names __name__ and A and B MyClass not a name in the __main__ namespace. The "Class __main__.MyClass " that you see is an attribute of the __name__ class, not the actual variable in the namespace. Typically, the __name__ class will be equal to the name with which you define it, but if you create the class programmatically by calling type , like you, it will still have __name__ , but will not necessarily be available through any name in the namespace.
Here is a simple example of the difference:
>>> A = type('MyClass', (object,), {}) >>> MyClass Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> MyClass NameError: name 'MyClass' is not defined
Just passing MyClass to type does not actually create a variable called MyClass . It is these actual variable names that are unique, not the internal concept of his name.
A class is the same as for another class if it is the same object of the class. Even if they have the same __name__ attribute, they can still be different objects.
source share