Structuring Modules with a Ubiquitous Base Class (Circular Dependencies)

andrew cooke andrew at
Wed Feb 4 23:49:51 CET 2009

Is there a good solution to the following problem?

I have a library whose components I would like to separate into
distinct modules.  These components inherit from a common base class
that provides common functionality (the inheritance is important only
for implementation; there's a separate ABC mechanism for typing).

Now as that stands, there is no problem.  Each module could import the
common base class.

Unfortunately the base class itself references many of the components
(the reason for this is that supplies operator implementations (like
__add__) which are shortcuts for the components themselves).

This leads to a circular dependency - the base class wants to import
the components, which in turn want to import the base class.

Is there any standard solution to this?


More information about the Python-list mailing list