[C++-sig] Sorry for my absence

Nick Rasmussen nick at ilm.com
Mon Mar 14 19:37:13 CET 2005


On Sat, 12 Mar 2005, Jonathan Brandmeyer wrote:

> On Fri, 2005-03-11 at 18:19 -0800, Nick Rasmussen wrote:
> > Given that there wasn't any way to make the right way work, there
> > are three options that I came up with to make this work with existing
> > python versions:
> > 
> > 1: have end-users modify their installed inspect.py and/or pydoc.py files
> > 2: replace inspect.isbuiltin dynamically on module load with a version
> >    that understands boost function types.
> > 3: fool pydoc into thinking that boost::python functions are instances
> >    of the builtin function type.
> 
> There is another option that I haven't had time to fully explore - make
> inspect.getmodule() work for a free Boost.Python.function.  I think that
> if the code that makes Boost.Python.class objects' __module__ member
> work was applied to free function objects, a trivial change could be
> made to inspect.getmodule().

I thought about that as well, but here's what I came up with, given
the premise that we don't want to do #1 or #2 above:

I checked the rest of the types that show up in inspect.getfile that
we could possibly use to fake out the existing code: FunctionType,
CodeType, FrameType, MethodType, aren't subclassable.  ModuleType
is, but that doesn't seem like a good candidate to subclass, since
pydoc will ignore the function again.

ClassType isn't subclassable, however inspect.isclass has an extra case that
doesn't show up in the other is* functions:  hasattr(object,'__bases__')
If we add a __bases__ attribute to the function objects, inspect.isclass
will think its a class, and then if we stash a pointer to the module in
__module__ the lookup would work properly.  Unfortunately, if inspect.isclass
reports the function as a class, pydoc tries to document it as such :/

-nick




More information about the Cplusplus-sig mailing list