[PyQt] support for __slots__ / no-__dict__ instances in SIP/PyQt?

Hans Meine meine at informatik.uni-hamburg.de
Wed Nov 3 14:36:32 GMT 2010


Hi Phil,

I have the personal habit of using __slots__ to explicitly list all "member 
variables", i.e. instance attributs my classes have.  IIRC, the original 
intention behind this was to allow for efficient classes, i.e. ones that do 
not have one __dict__ per instance.  But as a side effect, this leads to 
exceptions being thrown when one tries to add attributes that were not 
specified, and I am using this as a desired constraint, i.e. I want to force 
myself to specify the attributes I use in the class, as a sort of developer 
documentation.

However, this fails as soon as one of the base classes has a __dict__, and 
guess what?  QObject and friends have.

Is there a good reason why this must be the case, or would it be a desirable 
feature of SIP to suppress the __dict__s?  (BTW: boost::python does so 
unconditionally.)

I can imagine that people are used to "attaching" data members to widgets, but 
I would happily ditch this and instead get notified about incomplete 
__slots__.

Have a nice day,
  Hans


More information about the PyQt mailing list