The ability to override the class dictionary using a __slots__ declaration is supported only by new-style classes. When you add a __slots__ declaration to an old-style class it just creates a class attribute called '__slots__'.

If you want to override the dictionary for a class, then ensure that the class is a new-style class. You can convert an old-style class to a new-style class by inheriting from object.

In the following example the KeyedRef class is an old-style class (no inheritance). The __slots__ declaration in this class creates a class attribute called '__slots__', the class dictionary is unaffected. The KeyedRef2 class is a new-style class so the __slots__ declaration causes special compact attributes to be created for each name in the slots list and saves space by not creating attribute dictionaries.

  • Python Glossary: New-style class.
  • Python Language Reference: New-style and classic classes, __slots__.