Explicitly state that the default implementation is registered for `object`

Thanks to Gustavo Carneiro for the suggestion.
This commit is contained in:
Łukasz Langa 2013-05-31 12:31:11 +02:00
parent b8e9268074
commit 82261fe5e1
1 changed files with 7 additions and 3 deletions

View File

@ -134,13 +134,17 @@ argument::
Where there is no registered implementation for a specific type, its Where there is no registered implementation for a specific type, its
method resolution order is used to find a more generic implementation. method resolution order is used to find a more generic implementation.
The original function decorated with ``@singledispatch`` is registered
for the base ``object`` type, which means it is used if no better
implementation is found.
To check which implementation will the generic function choose for To check which implementation will the generic function choose for
a given type, use the ``dispatch()`` attribute:: a given type, use the ``dispatch()`` attribute::
>>> fun.dispatch(float) >>> fun.dispatch(float)
<function fun_num at 0x104319058> <function fun_num at 0x104319058>
>>> fun.dispatch(dict) >>> fun.dispatch(dict) # note: default implementation
<function fun at 0x103fe4788> <function fun at 0x103fe0000>
To access all registered implementations, use the read-only ``registry`` To access all registered implementations, use the read-only ``registry``
attribute:: attribute::
@ -152,7 +156,7 @@ attribute::
>>> fun.registry[float] >>> fun.registry[float]
<function fun_num at 0x1035a2840> <function fun_num at 0x1035a2840>
>>> fun.registry[object] >>> fun.registry[object]
<function fun at 0x103170788> <function fun at 0x103fe0000>
The proposed API is intentionally limited and opinionated, as to ensure 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 it is easy to explain and use, as well as to maintain consistency with