Explicitly state that the default implementation is registered for `object`
Thanks to Gustavo Carneiro for the suggestion.
This commit is contained in:
parent
b8e9268074
commit
82261fe5e1
10
pep-0443.txt
10
pep-0443.txt
|
@ -134,13 +134,17 @@ argument::
|
|||
|
||||
Where there is no registered implementation for a specific type, its
|
||||
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
|
||||
a given type, use the ``dispatch()`` attribute::
|
||||
|
||||
>>> fun.dispatch(float)
|
||||
<function fun_num at 0x104319058>
|
||||
>>> fun.dispatch(dict)
|
||||
<function fun at 0x103fe4788>
|
||||
>>> fun.dispatch(dict) # note: default implementation
|
||||
<function fun at 0x103fe0000>
|
||||
|
||||
To access all registered implementations, use the read-only ``registry``
|
||||
attribute::
|
||||
|
@ -152,7 +156,7 @@ attribute::
|
|||
>>> fun.registry[float]
|
||||
<function fun_num at 0x1035a2840>
|
||||
>>> fun.registry[object]
|
||||
<function fun at 0x103170788>
|
||||
<function fun at 0x103fe0000>
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue