Simple Traits

Ethan Furman ethan at stoneleaf.us
Sat Mar 27 09:13:01 EDT 2010


Wow.

I just stumbled across one of Michele Simionato's offerings, called 
simple traits (strait for short) which looks *really* cool.

You can find it here: http://pypi.python.org/pypi/strait/0.5.1

Extremely quick summary:

Instead of multiple inheritance, with it's range of problems, use single 
inheritance for the basics, and include traits for various extra 
functionality that you want your class to have.

As a side note, one of his blog entries at Artima talks about using 
composition instead of mixins when constructing a class, e.g. by doing:

class foo(object):
   import baz
   def __init__(self):
     self.baz.do_something()

which has the benefit (over mixins) of avoiding name-space pollution, as 
well as being able to tell where your methods are coming from.  The cool 
thing (to me, at least) was the realization of being able to use import 
statements in class construction.

Thanks, Michele!!

~Ethan~



More information about the Python-list mailing list