weissjeffm / multimethods

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

Can't decorate or replace multimethod function #1

Closed weissjeffm closed 10 years ago

weissjeffm commented 10 years ago

If you write

@mymethod.method((MyClass))
def mymeth_myclass(x):
   ....

mymeth_myclass = trace(mymeth_myclass)  # trace is a decorator

then the dispatch will not be traced. You would have to re-decorate afterward. This kind of blows because it means you can't do anything to multimethod functions once they've been defined.

multimethods probably should just resolve the name of the function into the actual function object, every time it's called. slow, but less surprising behavior.

weissjeffm commented 10 years ago

I actually tried to implement the fix for this, which led to some observations:

So that brings me back to how to solve the original problem: how do i trace multimethods? One obvious solution is to trace multimethods differently than regular functions. But seems like the trace lib and multimethod lib should not know about each other.

weissjeffm commented 10 years ago

So what I ended up doing to trace multimethods is just change the definition of what counts as a "function" to include multimethods. The individual dispatch functions are not traced but really this only leaves out which method was selected.