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

Antoine Pitrou solipsis at pitrou.net
Wed May 29 08:16:02 CEST 2013


On Wed, 29 May 2013 08:08:14 +0200
Antoine Pitrou <solipsis at pitrou.net> wrote:
> On Wed, 29 May 2013 12:40:32 +1000
> Nick Coghlan <ncoghlan at gmail.com> wrote:
> > On Wed, May 29, 2013 at 5:41 AM, Russell E. Owen <rowen at uw.edu> wrote:
> > > In article <C9841B1F-80F3-4E77-83E6-F71859524BC8 at langa.pl>,
> > >  Łukasz Langa <lukasz at langa.pl> wrote:
> > >
> > >> Hello,
> > >> Since the initial version, several minor changes have been made to the
> > >> PEP. The history is visible on hg.python.org. The most important
> > >> change in this version is that I introduced ABC support and completed
> > >> a reference implementation.
> > >>
> > >> No open issues remain from my point of view.
> > >
> > > Is it true that this cannot be used for instance and class methods? It
> > > dispatches based on the first argument, which is "self" for instance
> > > methods, whereas the second argument would almost certainly be the
> > > argument one would want to use for conditional dispatch.
> > 
> > Correct. OO and generic functions are different development paradigms,
> > and there are limitations on mixing them. Generic functions are for
> > stateless algorithms, which expect to receive all required input
> > through their arguments. By contrast, class and instance methods
> > expect to receive some state implicitly - in many respects, they
> > *already are* generic functions.
> 
> There are actual use cases for generic methods, think pickle.py.

That said, I admit this is a case where the generic method use is
private, i.e. is not exposed for other code to extend.

(the public extension protocol being in the form of plain methods:
__getstate__, etc.)

Regards

Antoine.




More information about the Python-Dev mailing list