So, I realized only today that __new__ deprecated for getting arguments, as from python 2.6 (it is not mentioned in the documentation, which is also incorrect from the point of view of the __new__ behavior of the __init__ call as far as I can see). This means that my functional code began to raise warnings, and I want to get rid of them. But I do not see an elegant way to get around.
I have a bunch of classes that perform optimization when they are built. So i
class Conjunction(Base): def __new__(cls, a, b): if a == True: return b elif b == True return a else: return super(Conjunction,cls).__new__(cls, a, b)
And so on (real versions cover many more cases). Unlike what Guido says in this answer (the only link to it I can find), my __new__ method uses its arguments and cannot replace with an overridden __init__ function.
The best I can do is split this into two parts:
def Conjunction(a, b): if a == True: return b elif b == True return a else: return ConjunctionImpl(a, b) class ConjunctionImpl(Base):
But it's just ugly and stinks to heaven. Am I missing an elegant way for the class constructor to return any arbitrary object based on the constructor parameters that it specified?
source share