[Python-Dev] PEP 443 - Single-dispatch generic functions (including ABC support)

Nick Coghlan ncoghlan at gmail.com
Sun May 26 03:37:03 CEST 2013


On Sun, May 26, 2013 at 9:07 AM, PJ Eby <pje at telecommunity.com> wrote:
> On Sat, May 25, 2013 at 4:16 PM, Łukasz Langa <lukasz at langa.pl> wrote:
>> So, the latest document is live:
>> http://www.python.org/dev/peps/pep-0443/
>>
>> The code is here:
>> http://hg.python.org/features/pep-443/file/tip/Lib/functools.py#l363

Hmm, I find the use of the variable name "dispatch_cache" for a cache
that dispatch() doesn't actually use to be confusing.

It also doesn't make sense to me that dispatch() itself bypasses the
cache - I would expect all the cache manipulation to be in dispatch(),
and there to be a separate "_find_impl()" function that is invoked to
handle cache misses.

If there's a good reason for dispatch() to bypass the cache without
refreshing it, then I suggest renaming the cache variable to
"impl_cache".

> We should probably also standardize on the term used for the
> registered functions.  The standard terminology is "method", but that
> would be confusing in Python, where methods usually have a self
> argument.  The PEP uses the term "implementation", and I think that
> actually makes a lot of sense: a generic function is composed of
> functions that implement the same operation for different types.

+1 on consistently using "implementation" as the name for individual
functions that are passed to register() and that dispatch() may
return. It's also consistent with the terminology we (or at least I)
tend to use about finding the implementation of methods based on the
type hierarchy.

Also +1 to your other docs comments - that info is in the PEP, and is
relevant to actually using the new generics in practice.

Cheers,
Nick.

--
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list