3.5 The psyco.compact type

Starting from version 1.4, Psyco exports two extension types: psyco.compact and psyco.compacttype. (In some future version, Psyco may be able to patch the features implemented by these types directly into the standard interpreter's built-in types).

class psyco.compact
A base class whose instances are stored more compactly in memory. Can be directly instantiated or subclassed. The instances behave roughly like normal Python instances, i.e. you can store and read attributes, and put methods and other attributes in the subclasses, including Python's special methods (__init__, __str__, etc.). Their advantages over regular instances are:

There are a few visible differences and limitations:

  1. Explicit use of __slots__ is forbidden.
  2. Weak references to instances are not allowed. (Please write me if you would like me to remove this limitation.)
  3. Instances are not based on a real dictionary; the __dict__ attribute returns a dictionary proxy (which however supports all dict operations, including writes).
  4. When assigning to __dict__, a copy of the data is stored into the instance; the dict and the instance do not reflect each other's future changes (they do in plain Python).
  5. Instances have a __members__ attribute which lists the current attributes, in the order in which they have been set.
  6. For internal reasons, the subclasses' __bases__ attribute will always contain psyco.compact as the last item, even if one or several other base classes were specified.
  7. Three methods __getslot__, __setslot__ and __delslot__ show up for internal purposes.

class psyco.compacttype
The metaclass of psyco.compact. It inherits from type. It means that when you subclass psyco.compact, your classes are by default of type psyco.compacttype instead of type. The sole purpose of this metaclass is to force psyco.compact to appear in the subclasses' bases, and to check for __slots__.

Note that you should not mix psyco.compacttype classes and normal classes in the same hierarchy. Although this might work, the instances will still each have an unused allocated dictionary.