[C++-sig] Re: sub module support in V2

David Abrahams david.abrahams at rcn.com
Thu Jun 6 01:25:46 CEST 2002


From: "Dave Hawkes" <daveh at cadlink.com>


> I don't like either of these alternatives, so I'm thinking of a quite
> different solution.
>
> Instead of linking directly to the parent module, just define the
sub-module
> with a dotted name.
>
> so we get:
>
> boost::python::module("outer").def("Test1", Test1).def(...
> boost::python::module("outer.inner1").def("Test2", Test2).def(...
> boost::python::module("outer.inner2").def("Test3", Test3).def(...
>
> This simplifies the chaining considerably as we can identify the parent
> modules in sys.modules (and verify that it belongs to the current
module).
> An attempt to reuse a previous sub-module will just return a reference to
> the existing one.
>
> An advantage of this is that a later call to the main module would return
a
> reference to the previously created one and give more coding flexibility.

I like it in principle, but the downside is that the absolute path to the
module is encoded in the source. You wouldn't be able to collect arbitrary
extension modules into a package later.

Got a workaround for that issue?






More information about the Cplusplus-sig mailing list