[PyQt] support for __slots__ / no-__dict__ instances in SIP/PyQt?
Phil Thompson
phil at riverbankcomputing.com
Thu Nov 4 11:07:10 GMT 2010
On Wed, 3 Nov 2010 15:36:32 +0100, Hans Meine
<meine at informatik.uni-hamburg.de> wrote:
> 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.)
The good reason is that it is a useful feature and removing it would break
many applications.
> 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__.
While SIP could be enhanced to have that as an option, PyQt would never
use it.
Phil
More information about the PyQt
mailing list