My goal is to use __new__() in PetBuyer like a factory for the animals class.
My reason for doing this are that the syntax PetBuyer('Dog') is convenient in my program.

ADDED2
My reason for doing this is the following. What I have to code is complex for me in the sense that, per see, I cannot infer the proper class design. So I resort to code my problem in anyway I can an refactor as I better understand it. However, with the situation that arise above, it will be too early for me to refactor. I have yet to understand the interaction between some components of my problem, and changing the base class at runtime will help me to do it. I will be more comfortable for refactoring afterward.

You don't. You name the correct bases the time you create the class.
–
delnanApr 27 '12 at 20:34

a PetBuyer is almost certainly not a kind of Pet, you would normally compose the two types by adding the Pet instances as attributes on the PetBuyer. "Grandma has-a dog" rather than "Grandma is-a special kind of dog"
–
IfLoopApr 27 '12 at 22:41

3 Answers
3

Based on your new information, it sounds like you need to create types dynamically. You certainly are not obligated to create a class suite to describe those types, you can create them at run time by calling the type function directly:

When you are overriding __new__ that class is already in existence, anyway __new__ is used to create instances of a given class, what you want can be done via a metaclass, which can act like a factory for classes

After seeing OP's edit I will say forget all of the above, you don't need any metaclass, just a simple PetBuyer class which is composed of (has a) Pet , so question is why can't you just pass the pet to PetBuyer e.g.

I added my use case. I tried your solution, but I couldn't change your code to make my use case work. I couldn't pass any argument to the metaclass M.
–
Nicolas Essis-BretonApr 27 '12 at 22:38

I chose the post of TokenMacGuy as it answers more my immediate question (please see my post below). But as soon as I can, I will refactor my code per your post. Thank you.
–
Nicolas Essis-BretonApr 29 '12 at 17:25