The documentation design.rst should clearly state that one must either use the approach using Dispatcher() or the approach using @dispatch. These two cannot be mixed.
Currently the example in Namespaces and dispatch merely states
# f = Dispatcher('f') # no need to create Dispatcher ahead of time
But actually in the sequence
f = Dispatcher('f')
@f.register(int)
def inc(x):
return x + 1
@dispatch(float)
def f(x):
return x - 1
the @dispatch overwrites f with a new Dispatcher object, and the registration f(int) is lost. This is by design: @dispatch uses the namespace to store names and definitions, while Dispatcher is unaware of namespaces.
The documentation design.rst should clearly state that one must either use the approach using
Dispatcher()or the approach using@dispatch. These two cannot be mixed.Currently the example in Namespaces and dispatch merely states
# f = Dispatcher('f') # no need to create Dispatcher ahead of timeBut actually in the sequence
the @dispatch overwrites
fwith a new Dispatcher object, and the registrationf(int)is lost. This is by design:@dispatchuses thenamespaceto store names and definitions, whileDispatcheris unaware ofnamespaces.