In the following snippet the class returned by the type
call is named “abc.Y”, why? It’s defined in the “main” (in this case) module, after all (certainly not in any “abc” module) so I would expect it to be called “main.Y”.
from abc import ABC
class X(ABC):
pass
type('Y', (X,), {})
Replacing the type
call with a more traditional class definition class Y(X): pass
, results in the name being “main.Y”, as one would expect. Interestingly, the name of X
is “main.X” which is also what you’d expect.
I don’t see how dynamically creating the subclass of X
, in this case, should somehow make the name to be prefixed with “abc.”, even as X
itself derives from ABC
?
I can’t find anything in the documentation that should hint at the reason behind this naming behaviour. I’ve read up on abc.ABC
and type
. Maybe I am missing something very obvious?