Bug in New Style Classes

David MacQuigg dmq at gain.com
Thu Jun 17 04:15:35 CEST 2004


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

*************************************************************     *
* David MacQuigg, PhD              * email:  dmq at gain.com      *  *
* IC Design Engineer               * phone:  USA 520-721-4583  *  *  *
* Analog Design Methodologies                                  *  *  *
*                                  * 9320 East Mikelyn Lane     * * *
* VRS Consulting, P.C.             * Tucson, Arizona 85710        *
*************************************************************     *



More information about the Python-list mailing list