peps: Explicitly state that the default implementation is registered for `object`
May 31, 2013
10:31 a.m.
http://hg.python.org/peps/rev/4d6c827944c4 changeset: 4920:4d6c827944c4 user: Ćukasz Langa <lukasz@langa.pl> date: Fri May 31 12:31:11 2013 +0200 summary: Explicitly state that the default implementation is registered for `object` Thanks to Gustavo Carneiro for the suggestion. files: pep-0443.txt | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pep-0443.txt b/pep-0443.txt --- a/pep-0443.txt +++ b/pep-0443.txt @@ -134,13 +134,17 @@ 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 @@ >>> 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 -- Repository URL: http://hg.python.org/peps
4850
Age (days ago)
4850
Last active (days ago)
0 comments
1 participants
participants (1)
-
lukasz.langa