__slots__ and multiple inheritance

Dave Reed dreed at capital.edu
Sat Dec 14 14:41:40 EST 2002


__slots__ doesn't seem to work as I expect when I use mixins/multiple
inheritance:

I've got a BaseSQL class (see code at bottom of message) in which I
define __slots__ (I started using it so pychecker didn't complain
about me using the instance variables from the other base class). I
left out "values" from __slots__, but it still lets me assign to
self.values.

Also, If I put the same __slots__ in the StudentSQL class, I get the
error:

    class Student(BaseSQL, StudentSQL):
TypeError: multiple bases have instance lay-out conflict

Can anyone explain to me how this should work?

Note: this is Python 2.2.1 that came with Red Hat 8.0.

Thanks,
Dave



class BaseSQL(object):

   # so pychecker doesn't complain
   __slots__ = ['sql_types', 'types', 'pkey', 'table', 'table_seq',
                'map_cols', 'map_dict']

   def __init__(self, values=None, start_with_defaults=1):
      
      if start_with_defaults:
         self.values = UtilPSQL.get_default_values(self.types)
      else:
         self.values = {}

      if values != None:
         for k in values.keys():
            if k in self.sql_types.keys():
               self.values[k] = values[k]


class StudentSQL(object):

   def __init__(self):

      self.sql_types = StudentSQLTypes.sql_types
      self.types = StudentSQLTypes.types
      self.pkey = 'id'
      self.table = 'student'
      self.table_seq = 'student_seq'
      self.map_cols = ()
      self.map_dict = {}


class Student(BaseSQL, StudentSQL):
       
   def __init__(self, values=None, start_with_defaults=1):
      
      StudentSQL.__init__(self)
      BaseSQL.__init__(self, values, start_with_defaults)





More information about the Python-list mailing list