I solved the problem in other way that seems to be ok.
Let's consider a C++ library that contains two classes:
- Foo
- FooFactory
Wrapper library contains package libfoo
(created in Python C API) and pythonic package foo
(created in ordinary python). We don't access libfoo
package directly, but import foo
.
Package foo
's __init__.py
:
from libfoo import Foo, FooFactory
# both are naked wrappers with ugly API derived from C++
# I defined some pythonic sugar that makes them nice to use
class FooPythonicGoodies(object):
# add pythonic goodies here
def quack(self):
pass
# Merge them
Foo.__bases__ = Foo.__bases__ + (FooPythonicGoodies,)
Now, when anywhere in the sources I do this:
from foo import Foo, FooFactory
a = Foo()
a.quack()
# Factory is a C++ wrapped class that returns wrapped foo
# objects WITH FooPythonicGoodies!
factory = FooFactory()
b = factory.create_foo()
b.quack() # that works too!
That way I can polish rather un-pythonic C++ classes with a pythonic API sugar.