Since there is no actual question in the question, I am going to take it literally:
Whats wrong doing it dynamically?
Well, it is practically unreadable, extremely opaque and non-obvious to the user of your code (that includes you in a month :P).
From my experience (quite limited, I must admit, unfortunately I don't have 20 years of programming under the belt), a need for such solutions indicates, that the class structure is not well defined, - means, there's almost always a better, more readable and less arcane way to do such things.
For example, if you really want to define base classes on the fly, you are better off using a factory function, that will return appropriate classes according to your needs.
Another take on the question:
Whats wrong doing it dynamically?
In your current implementation, it gives me a "maximum recursion depth exceeded" error. That happens, because A.__new__
calls itself from within itself indefinitely (since it inherits from itself and from B
).
10: Inside A.__new__
, "cls" is set to <class '.A'>
. Inside the constructor you define a class C
, which inherits from cls
(which is actually A
) and another class B
. Upon instantiating C
, its __new__
is called. Since it doesn't define its own __new__
, its base class' __new__
is called. The base class just happens to be A
.
20: GOTO 10