| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 
 |  
# objet quelconque
class UnObjet:
 
    def __init__(self,x):
        self.x = x
        print('foo')
 
 
 
# classe qui modifie un objet
class Mod:
 
    def __new__(cls,objet,*args):
        objet.__class__ = type('**',(cls,objet.__class__),{})
        return objet
 
    def __init__(self,*args):
        print('mod')
 
    @property
    def y(self):
        return self.x + 2
 
 
 
#classe qui cree un objet et le modifie
class Mod2(Mod):
 
    #ici il faut surcharger __new__
    def __new__(cls,x,z):
        instance = Mod.__new__(cls,UnObjet(x))
        return instance
 
    def __init__(self,x,z):
 
        Mod.__init__(self)
        print('mod2')
 
    #d'autres propriétés ici
 
 
 
 
objet = Mod(UnObjet(5))
print(objet.y)
#foo
#mod
#7
objet = Mod2(8,3)
print(objet.y)
#foo
#mod
#10 | 
Partager