Bug in New Style Classes
Michele Simionato
michele.simionato at poste.it
Thu Jun 17 04:21:44 EDT 2004
David MacQuigg <dmq at gain.com> wrote in message news:<rmu1d09qiqtosgdq1vavv3736sb62bktri at 4ax.com>...
> I have what looks like a bug trying to generate new style classes with
> a factory function.
>
> class Animal(object): pass
> class Mammal(Animal): pass
>
> def newAnimal(bases=(Animal,), dict={}):
> class C(object): pass
> C.__bases__ = bases
> dict['_count'] = 0
> C.__dict__ = dict
> return C
>
> Canine = newAnimal((Mammal,))
> TypeError: __bases__ assignment: 'Mammal' deallocator differs from
> 'object'
>
> If I remove the 'object' from the class C(object) statement, then I
> get a different, equally puzzling error message:
>
> TypeError: __bases__ items must be classes
>
> The function works only if I remove 'object' from all base classes.
>
> -- Dave
This is not a bug. The developers removed the possibility to change
the bases of a new-style class. Probably because it could not be done
reliably (I don't know). But I am happy my base classes cannot
change under my feet ;)
You can just create a new class with new bases if you wish.
Michele Simionato
More information about the Python-list
mailing list