__nonzero__ does not work
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
PyBindGen |
New
|
Undecided
|
Unassigned |
Bug Description
I can not add the special method __nonzero__ to my wrapped classes.
Here is a test that shows the problem.
(Adding __len__ and __getitem__ works, but __nonzero__ does not.
I'm using Python 2.7 and PyBindGen 0.15.0.)
----- Test.h: -----
class X0 {
public:
operator bool() const { return false; }
};
class X1 {
public:
bool __nonzero__() const { return false; }
};
class X2 {
public:
bool nonZero() const { return false; }
};
class X3 {};
inline bool __nonzero__(const X3&) { return false; }
class X4 {};
inline bool nonZero(const X4&) { return false; }
----- TestBindings.py -----
import pybindgen
param = pybindgen.param
retval = pybindgen.retval
Test = pybindgen.
Test.add_
X0 = Test.add_
X0.add_
X0.add_
X1 = Test.add_
X1.add_
X1.add_
X2 = Test.add_
X2.add_
X2.add_
X3 = Test.add_
X3.add_
X3.add_
X4 = Test.add_
X4.add_
X4.add_
----- Main.py -----
import Test
print bool(Test.X0())
print bool(Test.X1())
print bool(Test.X2())
print bool(Test.X3())
print bool(Test.X4())
----- Expected result -----
Main.py produces the output
False
False
False
False
False
----- Observed result -----
Main.py produces the output
True
True
True
True
True
I took a look at the C code generated by PyBindGen. docs.python. org/c-api/ typeobj. html#number- object- structures
(Fortunately PyBindGen generated exceptionally readable code.)
There I could see that my __nonzero__ method was added to the tp_methods member of the type object.
It should have been added as the nb_nonzero member of the tp_as_number member of the type object; see
http://
So it seems that either I have added __nonzero__ the wrong way, or this is a PyBindGen bug.