From: David Abrahams (david.abrahams_at_[hidden])
Date: 2001-11-14 08:33:48
----- Original Message -----
From: "Ivan A. Vigasin" <vig_at_[hidden]>
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "<stdin>", line 5, in __init__
> TypeError: unbound method __init__() must be called with instance as
> Maybe result depends on python's or boost's version?
Perhaps. What versions are you using?
The Boost code in question hasn't changed in a year. I was using
Python2.2b1, but it's hard to imagine that Python can get any control over
this! The code in question is at the bottom of the message.
OK, I believe that Python2.2 is just being liberal, here. If you look at the
code below, Boost.Python only does that method unwinding when looking at
/base/ class attributes. So, this should work for you:
self.x = 'x'
__init_Base_ = Base.__init__
self.y = 'y'
I guess it would be good to have a more explicit mechansim for this, eh?
Oh, please try this one as well:
class BasePrime(Base): pass
I think that one should work, too, and it's a bit more elegant.
ref local_attribute = m_name_space.get_item(string(name).reference());
// In case there are no bases...
// Check bases
for (std::size_t i = 0; i < m_bases.size(); ++i)
PyErr_Clear(); // we're going to try a base class
else if (PyErr_Occurred())
break; // Other errors count, though!
PyObject* base_attribute =
if (base_attribute != 0)
// Unwind the actual underlying function from unbound Python
// methods in case of multiple inheritance from real Python
// classes. Python stubbornly insists that the first argument
// method must be a true Python instance object otherwise. Do
// unwrap bound methods; that would interfere with intended
reinterpret_cast<PyMethodObject*>(base_attribute)->im_self == 0)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk