[PyKDE] Sip wishlist item: Parameter typechecking enhancement

Nigel Stewart ns at fluent.com
Fri Jul 8 20:33:35 BST 2005


Hello all,

We have a C++ constructor that takes either a Foo pointer
or PyObject pointer as an argument.  The PyObject needs
to be python-wrapped Foo, a runtime check is applied and
an assertion raised if the python object can't be "cast"
to a Foo.

The reason for this arrangement is that we want to do
some reference counting for python managed instances
of Foo.

Ideally, we would be able to do some kind of annotation
that the parameter is Foo, but should be passed to the
PyObject version of the constructor:

class Bar
{
public:
     Bar(Foo & /PyObject/);
     ...
}

Currently we are accepting a SIP_PYOBJECT, but properly
handling the typechecking is going to require custom
%MethodCode.

class Bar
{
public:
     Bar(SIP_PYOBJECT);
     ...
}

There is possibly an elegant exception handling solution to
this too, does anyone else see a benefit in sip providing
typechecking of generic python parameters in this annotated
kind of manner.  (Rather than bugging Phil directly!)

Nigel




More information about the PyQt mailing list