Overview

-- restructuredtext --

Clojure-like multimethods for Python

This package is about implementing multimethods in a style that is very much like Clojure. There is a way to declare dispatch functions over parameters and use them to distinguish between different implementations of a multimethod and there is an adhoc hierarchy of objects aside the existing hierarchy of classes and instances.

What is implemented

For now have a look at the testcases to see what is implemented, as this is still a hackish project without much documentation. There are shots at most of the needed parts and I'd say their functionality is somewhere at 80% of what would be needed, but none of it is actually production quality. It's more a research thing.

What is still planned to implement

  • when adhoc hierarchies and classes are intermixed, isa doesn't work right. I need to fully check all MRO of all classes and all derivations to make sure I catch all variations. This will need proper optimization to be performant.
  • isa currently checks for iterators, but that's stupid. It should really only check for tuples and see anything else as a normal object and not magically see anything as a sequence.
  • there is currently no optimization and caching whatsoever on method lookup. This obviously will have to change.
  • loop detection in prefer_method is currently only implemented for direct conflicts, not for loops larger than 2.
  • I think multimethods should implement the context protocol so that I can have a with block that creates a dynamically scoped version of the multimethod that can be extended inside the with block to dynamically extend multimethods and properly clean up afterwards.