Re: Swapping superclass from a module

2009-05-17 Thread Terry Reedy
Peter Otten wrote: Terry Reedy wrote: If the names of superclasses is resolved when classes are instantiated, the patching is easy. If, as I would suspect, the names are resolved when the classes are created, before the module becomes available to the importing code, then much more careful a

Re: Swapping superclass from a module

2009-05-17 Thread Emanuele D'Arrigo
Wow, thank you all. Lots of ideas and things to try! I wish I knew which one is going to work best. The module I'm trying to (monkey!) patch is pxdom, and as it is a bit long (5700 lines of code in one file!) I'm not quite sure if the simplest patching method will work or the more complicated o

Re: Swapping superclass from a module

2009-05-17 Thread Peter Otten
Terry Reedy wrote: > Steven D'Aprano wrote: >> On Sat, 16 May 2009 09:55:39 -0700, Emanuele D'Arrigo wrote: >> >>> Hi everybody, >>> >>> let's assume I have a module with loads of classes inheriting from one >>> class, from the same module, i.e.: >> [...] >>> Now, let's also assume that myFile.py

Re: Swapping superclass from a module

2009-05-17 Thread Michele Simionato
Try this: class Base(object): pass class C(Base): pass class NewBase(object): pass C.__bases__ = (NewBase,) help(C) -- http://mail.python.org/mailman/listinfo/python-list

Re: Swapping superclass from a module

2009-05-16 Thread Terry Reedy
Steven D'Aprano wrote: On Sat, 16 May 2009 09:55:39 -0700, Emanuele D'Arrigo wrote: Hi everybody, let's assume I have a module with loads of classes inheriting from one class, from the same module, i.e.: [...] Now, let's also assume that myFile.py cannot be changed or it's impractical to do

Re: Swapping superclass from a module

2009-05-16 Thread Steven D'Aprano
On Sat, 16 May 2009 09:55:39 -0700, Emanuele D'Arrigo wrote: > Hi everybody, > > let's assume I have a module with loads of classes inheriting from one > class, from the same module, i.e.: [...] > Now, let's also assume that myFile.py cannot be changed or it's > impractical to do so. Is there a w

Re: Swapping superclass from a module

2009-05-16 Thread Arnaud Delobelle
"Emanuele D'Arrigo" writes: > On May 16, 8:17 pm, Arnaud Delobelle wrote: >> # Insert Wedge into each subclass of modfoo.Base >> for subclass in modfoo.Base.__subclasses__(): >>     if subclass.__module__ != 'modfoo': continue >>     attrs = dict(item for item in subclass.__dict__.items() >>    

Re: Swapping superclass from a module

2009-05-16 Thread Emanuele D'Arrigo
On May 16, 8:17 pm, Arnaud Delobelle wrote: > # Insert Wedge into each subclass of modfoo.Base > for subclass in modfoo.Base.__subclasses__(): >     if subclass.__module__ != 'modfoo': continue >     attrs = dict(item for item in subclass.__dict__.items() >                       if item[0][:2] !=

Re: Swapping superclass from a module

2009-05-16 Thread Arnaud Delobelle
"Emanuele D'Arrigo" writes: > Hi everybody, > > let's assume I have a module with loads of classes inheriting from one > class, from the same module, i.e.: > > ## myFile.py > class SuperClass(object) > class SubClass1(SuperClass) > class SubClass2(SuperClass) > class SubClass3(SuperClass) > > In