[Pyrex] Pyrex and __slots__?

Andreas Kostyrka andreas at mtg.co.at
Tue Aug 12 19:30:23 CEST 2003


Am Mon, 2003-08-11 um 19.34 schrieb Jeremy Fincher:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> I noticed when I moved a Python class to Pyrex that my __slots__ declaration 
> no longer prevents an instance __dict__ from being created.  Why is this, and 
> what needs to be done to allow __slots__ to do its job?
Well, why:
Pyrex doesn't provide the attributes of a class to the class
constructor. Instead it sets them later.
So __dict__ is created by the default type constructor.

Basically pyrex does something like this:

class A(object):
   __slots__ = ["a","b"]
   def __init__(self):
      self.a = 0
      self.b = 0

gets into something like:
class A(object): pass

def A___init__(self):
   self.a = 0
   self.b = 0

A.__slots__ = ["a","b"]
A.__init__ = A___init__

Andreas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://lists.copyleft.no/pipermail/pyrex/attachments/20030812/74d03899/attachment.bin


More information about the Pyrex mailing list