How to create child class instance using some magic in parent __new__?
问题 For example, creating custom number types in following hierarchy Number Complex Real Int Float with logic in __new__ methods: class Number: def __new__(cls, value): if isinstance(value, complex): return Complex(value) elif isinstance(value, (int, float)): return Real(value) else: raise TypeError('Ну ты и мудак!!!') def __init__(self, value): self.value = value class Complex(Number): pass class Real(Number): def __new__(cls, value): if isinstance(value, int): return Int(value) elif isinstance