Question: Is there a reasonable way in Python to implement mixin behavior similar to that found in Ruby -- that is, without using inheritance?

```
class Mixin(object):
    def b(self): print "b()"
    def c(self): print "c()"

class Foo(object):
    # Somehow mix in the behavior of the Mixin class,
    # so that all of the methods below will run and
    # the issubclass() test will be False.

    def a(self): print "a()"

f = Foo()
f.a()
f.b()
f.c()
print issubclass(Foo, Mixin)

```

I had a vague idea to do this with a class decorator, but my attempts led to confusion. Most of my searches on the topic have led in the direction of using inheritance (or in more complex scenarios, multiple inheritance) to achieve mixin behavior.

Answer: 
You can add the methods as functions:

```
Foo.b = Mixin.b.im_func
Foo.c = Mixin.c.im_func

```
```
from functools import partial
class Mixin(object):
    @staticmethod
    def b(self): print "b()"
    @staticmethod
    def c(self): print "c()"

class Foo(object):
    def __init__(self, mixin_cls):
        self.delegate_cls = mixin_cls

    def __getattr__(self, attr):
        if hasattr(self.delegate_cls, attr):
            return partial(getattr(self.delegate_cls, attr), self)

    def a(self): print "a()"

f = Foo(Mixin)
f.a()
f.b()
f.c()
print issubclass(Foo, Mixin)

```

This basically uses the `Mixin` class as a container to hold *ad-hoc* functions (not methods) that behave like methods by taking an object instance (self) as the first argument. `__getattr__` will redirect missing calls to these methods-alike functions.

This passes your simple tests as shown below. But I cannot guarantee it will do all the things you want. Make more thorough test to make sure.

```
$ python mixin.py 
a()
b()
c()
False

```