Revision adf385c7 lib/opcodes.py

b/lib/opcodes.py
52 52
    __slots__ attribute for this class.
53 53

  
54 54
    """
55
    slots = self._all_slots()
55 56
    for key in kwargs:
56
      if key not in self.__slots__:
57
      if key not in slots:
57 58
        raise TypeError("Object %s doesn't support the parameter '%s'" %
58 59
                        (self.__class__.__name__, key))
59 60
      setattr(self, key, kwargs[key])
......
69 70

  
70 71
    """
71 72
    state = {}
72
    for name in self.__slots__:
73
    for name in self._all_slots():
73 74
      if hasattr(self, name):
74 75
        state[name] = getattr(self, name)
75 76
    return state
......
88 89
      raise ValueError("Invalid data to __setstate__: expected dict, got %s" %
89 90
                       type(state))
90 91

  
91
    for name in self.__slots__:
92
    for name in self._all_slots():
92 93
      if name not in state:
93 94
        delattr(self, name)
94 95

  
95 96
    for name in state:
96 97
      setattr(self, name, state[name])
97 98

  
99
  @classmethod
100
  def _all_slots(cls):
101
    """Compute the list of all declared slots for a class.
102

  
103
    """
104
    slots = []
105
    for parent in cls.__mro__:
106
      slots.extend(getattr(parent, "__slots__", []))
107
    return slots
108

  
98 109

  
99 110
class OpCode(BaseOpCode):
100 111
  """Abstract OpCode.

Also available in: Unified diff