[C++-sig] custom from_python

David Abrahams david.abrahams at rcn.com
Fri May 31 21:58:30 CEST 2002


From: "Ralf W. Grosse-Kunstleve" <rwgk at yahoo.com>


> I am really impressed by the nice mechanism for registering a custom
> to_python conversion.
> What is the best way to define and register an equivalent custom
> from_python converter?

Have you looked at lvalue_from_pytype? The documentation is quite complete.

If you don't want to convert a particular Python type but would instead
like to convert, e.g. any Python sequence, take a look at the
implementation of lvalue_from_pytype instead. The low-level interfaces it
uses are not documented, but it's pretty simple. If you wanted to make and
document a more-general from_python converter registration facility which
included a way to customize matching of Python types, I'd be happy to put
it in the library.

> I am looking at the code in src/converter/from_python.cpp.
> Most built-in types seem to go through slot_rvalue_from_python.
> Should I use this, too?

So far that's an implementation detail of the library; it's doing a very
specific job which involves looking at a slot in the Python type to see if
a conversion function is supported... so, probably not, unless it's an
exact fit. In that case, it need to be documented and moved to a
publicly-accessible place.

-Dave








More information about the Cplusplus-sig mailing list