...one of the most highly
regarded and expertly designed C++ library projects in the
world. — Herb Sutter and Andrei
This page defines two concepts used to describe classes which manage a Python objects, and which are intended to support usage with a Python-like syntax.
Ris itself an TypeWrapper, a member function invocation of the form
x.some_function(a1, a2,...an)always has semantics equivalent to:
extract<R>(x.attr("some_function")(object(a1), object(a2),...object(an)))()When the
Ris an TypeWrapper, the result type may be constructed by taking direct posession of:
x.attr("some_function")(object(a1), object(a2),...object(an)).ptr()[see caveat below]
X. For a given TypeWrapper
T, a valid constructor expression
T(a1, a2,...an)builds a new
Tobject managing the result of invoking
Xwith arguments corresponding to
object(a1), object(a2),...object(an)When used as arguments to wrapped C++ functions, or as the template parameter to
extract<>, only instances of the associated Python type will be considered a match.
itemsreturns an object of type
list. Now suppose the user defines this
dictsubclass in Python:
>>> class mydict(dict): ... def items(self): ... return tuple(dict.items(self)) # return a tupleSince an instance of
mydictis also an instance of
dict, when used as an argument to a wrapped C++ function,
boost::python::dictcan accept objects of Python type
items()on this object can result in an instance of
boost::python::listwhich actually holds a Python tuple. Subsequent attempts to use list methods (e.g.
append, or any other mutating operation) on this object will raise the same exception that would occur if you tried to do it from Python.
Revised 13 November, 2002
© Copyright Dave Abrahams 2002.