From c8929600423f4d2d40e7113dbd2d9fe94be3961e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Langa?= Date: Fri, 24 May 2013 16:12:04 +0200 Subject: [PATCH] Document the `dispatch()` attribute --- pep-0443.txt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pep-0443.txt b/pep-0443.txt index 3065c6519..0fbfffe2a 100644 --- a/pep-0443.txt +++ b/pep-0443.txt @@ -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) + + >>> fun.dispatch(dict) + + 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.