Hey folks, 

One of my users spotted this, and I think it is an error in BP. It works
the same for any function exported. He states it more completely then I
could, So I will just forward what he sent to me:  

 

From: Ben Walker (TT) 
Sent: Friday, January 29, 2010 3:27 PM
To: Matthew Scouten (TT)
Subject: Boost.Python.function bug

 

>>> boost_func

<Boost.Python.function object at 0x011A0228>

>>> type(boost_func)

<type 'Boost.Python.function'>

>>> import types           

>>> isinstance(boost_func, types.BuiltinFunctionType)

True

>>> dir(boost_func)

['__call__', '__class__', '__cmp__', '__delattr__', '__doc__', '__eq__',
'__format__', '__ge__', '__getattribute__', '__gt__', '__hash__',
'__init__', '__le__', '__lt__', '__module__', '__name__', '__ne__',
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__self__',
'__setattr__', '__sizeof__', '__str__', '__subclasshook__']

>>> boost_func.__self__

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

AttributeError: 'Boost.Python.function' object has no attribute
'__self__'

>>> hasattr(boost_func, '__self__')

False

>>> 

 

dir() says Boost.Python.function objects have a __self__ member, but
accessing it throws an AttributeError. Furthermore, real builtin
functions have a __self__ member and some python libraries assume that
if something is an instance of a builtin function, it will have a
__self__ member. Testing via hasattr does function appropriately for the
actual behavior.

 

This was discovered while trying to use Sphinx's autodoc extension
(sphinx.pocoo.org) on a C++ library wrapped via Boost.Python.

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to