[C++-sig] [c++-sig] Is it a BUG? boost.python makes doctest impossible to recursive test.

甜瓜 littlesweetmelon at gmail.com
Mon Jun 11 14:17:37 CEST 2007


Thank you for your kind reply. I agree with you for extending inspect
module to cooperate with boost.python.

> However, I am getting <Boost.Python.function object at 0x....> for free
> functions (I thought your example was about the method C.func?):
>
> In [11]: type(norm)
> Out[11]: <type 'Boost.Python.function'>

Well, your result is true, but, in my case, I didn't invoke isfunction
or ismethod on C.func.
Indeed, ismethod(C.func) will return true. But inspect module use
'isfunction' to determine whether go recursively.
if ((inspect.isfunction(val) or inspect.isclass(val) or
isinstance(val, property))
     and self._from_module(module, val)):  .....
Here the val comes from C.__dict__['func']. If you print C.__dict__,
you will find a pair:
'func' : <Boost.Python.function object at 0x....>

So:
    t = BPLclass.__dict__['func']
    inspect.ismethod(t)   # False
    inspect.isfunction(t)  # False
    inspect.ismethod(BPLclass.func)   # True
    inspect.isfunction(BPLclass.func)  # False

    s = Pythonclass.__dict__['func']
    inspect.ismethod(t)   # False
    inspect.isfunction(t)  # True
    inspect.ismethod(Pythonclass.func)   # True
    inspect.isfunction(Pythonclass.func)  # False

Really interesting, Eh?

---
ShenLei



More information about the Cplusplus-sig mailing list