weissjeffm / multimethods

Multimethods for Python, inspired by Clojure
Other
16 stars 4 forks source link

Instance method support. #7

Open eanderton opened 6 years ago

eanderton commented 6 years ago

I was looking for a solid multimethod library and came across your project. As it happened, I was already 2 days into my own implementation when I decided to look deeper into what the Python community did in this area. Thank you for writing this project all those years ago.

The only thing that seemed to be missing was the ability to use self on dispatched class methods. I wrote this patch to provide that support, both as an optional argument on MultiMethod, and as a feature flag (so the default behavior may be set globally). This way, the implementation can remain backwards compatible with existing code.

Some of the decorators in the library couldn't be modified, due to quirks in Python's implementation of decorators. So @singledispatch and @multidispatch do not support the pass_self argument like @multimethod does.

In making sure that my changes didn't break existing behavior, I wrote additional tests for my own code, as well as those for the decorators in the library. The decorator tests are their own commit - feel free to cherry-pick that one if you like.

FYI, this changeset does not modify the version number. Should all this meet with your approval, I would be happy to add an additional commit for whatever version you think is appropriate.

Thank you for your consideration. I hope this PR finds you well.