Continuing the discussion from this question: Dynamically adding methods with or without metaclass, when doing the dynamic injetion, what is the difference and benefits/issues of doing it in the __new__ method vs. the __init__ method?
In the referenced question the new method is added by using setattr. If you do this in the__new__ method, you need to modify the dict parameter. Using the same example, it would be something like this:
class Meta(type)
def __new__(cls, clsname, bases, dct):
def my_method(self, x):
return x in self.letters
dct[my_method.__name__] = my_method
return super(Meta, cls).__new__(cls, clsname, bases, dct)