Document the `dispatch()` attribute

This commit is contained in:
Łukasz Langa 2013-05-24 16:12:04 +02:00
parent 7dda2675af
commit c892960042
1 changed files with 11 additions and 3 deletions

View File

@ -97,8 +97,8 @@ To enable registering lambdas and pre-existing functions, the
>>> fun.register(type(None), nothing)
The ``register()`` attribute returns the undecorated function which
enables decorator stacking, as well as creating unit tests for each
variant independently::
enables decorator stacking, pickling, as well as creating unit tests for
each variant independently::
>>> @fun.register(float)
... @fun.register(Decimal)
@ -126,9 +126,17 @@ When called, the generic function dispatches on the first argument::
3 spam
>>> fun(None)
Nothing.
>>> fun_num(1.23)
>>> fun(1.23)
0.615
To get the implementation for a specific type, use the ``dispatch()``
attribute::
>>> fun.dispatch(float)
<function fun_num at 0x104319058>
>>> fun.dispatch(dict)
<function fun at 0x103fe4788>
The proposed API is intentionally limited and opinionated, as to ensure
it is easy to explain and use, as well as to maintain consistency with
existing members in the ``functools`` module.