[Python-Dev] PEP 443 - Single-dispatch generic functions (including ABC support)
solipsis at pitrou.net
Wed May 29 08:08:14 CEST 2013
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.
(also, often a "stateless" function will eventually become stateful, if
used as part of a sufficiently complex application / library; e.g. some
logging will be added, or some kind of configuration object)
More information about the Python-Dev