[C++-sig] What if a Python override returns several values?
David Abrahams
dave at boost-consulting.com
Wed Sep 13 13:53:45 CEST 2006
Alex Mohr <amohr at pixar.com> writes:
> Clearly that's a true statement, but I don't see where boost::tuple is
> coming from. My eyes must be broken. I'll copy-paste the original
> code, quoted earlier in this message.
>
> void g(int& a, int& b) {
> boost::python::tuple tup = this->get_override("g")();
> a = ...extract an int from tup[0]...
> b = ...extract an int from tup[1]...
> }
>
> Compare this with the code you posted:
>
> >> python::tuple tup = this->get_override("g")();
> >> a = extract<t1>(tup[0]);
>
> The poster says the error message he gets is:
>
> TypeError: No registered converter was able to extract a C++ reference
> to type boost::python::tuple from this Python object of type tuple
>
> Where is boost::tuple coming into play?
Nowhere; I think it's my eyes that are broken, sorry!
> I didn't see that at all
> anywhere in the thread. In my reply to the poster, I removed the
> boost::python:: prefix from my code, so I mentioned "tuple" directly.
> Perhaps that's what was causing confusion? I meant boost::python::tuple.
>
> Regardless, unless I'm reading it wrong (please show me how!) I believe
> that the code you posted is identical to the original posted code.
Okay. Does it work if you don't use copy-initialization?
boost::python::tuple tup(this->get_override("g")());
?
Does this work?
boost::python::object t = this->get_override("g")();
boost::python::tuple tup(t);
what about:
boost::python::tuple tup
= this->get_override("g")().as<boost::python::tuple>();
??
>>>> There's almost never a reason to use call<> anymore! I should
>>>> deprecate it.
>>> Please don't -- I use it in some low-level code.
>>
>> Do you actually need it?
>
> I think so. It's in some template code, where the return type is a
> template parameter, and is allowed to be void, and IIRC, the problem was
> that saying "return extract<void>(callable(...));" doesn't work.
> Whereas saying "return call<void>(callable.ptr(), ...));" does. I guess
> I'd prefer to keep call<> around so I don't have to specialize the whole
> thing for the case of void.
>
> I can try reworking it to avoid using call later in the week and get
> back to you.
Don't bother; I understand your problem. You need a facility
something more like get_override and method_result, which the library
doesn't supply for your case.
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list