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

2013-05-31 Thread Nick Coghlan
On Fri, May 31, 2013 at 3:13 PM, Chris McDonough wrote: > On Fri, 2013-05-31 at 03:05 +0200, Łukasz Langa wrote: >> On 31 maj 2013, at 01:51, Łukasz Langa wrote: >> > >> Back to the point, though. I don't feel we should complicate the >> code, tests and documentation by introducing special handli

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

2013-05-30 Thread Chris McDonough
On Fri, 2013-05-31 at 03:05 +0200, Łukasz Langa wrote: > On 31 maj 2013, at 01:51, Łukasz Langa wrote: > > Back to the point, though. I don't feel we should complicate the > code, tests and documentation by introducing special handling > for methods. In terms of pure type-driven single dispatch,

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

2013-05-30 Thread Łukasz Langa
On 31 maj 2013, at 01:51, Łukasz Langa wrote: > On 31 maj 2013, at 01:47, Łukasz Langa wrote: > >> class State: >>def __init__(self): >>self.add.register(int, self.add_int) > > Ouch, I realized this is wrong just after I hit "Send". > self.add is a staticmethod so this registration

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

2013-05-30 Thread Łukasz Langa
On 31 maj 2013, at 01:47, Łukasz Langa wrote: > class State: >def __init__(self): >self.add.register(int, self.add_int) Ouch, I realized this is wrong just after I hit "Send". self.add is a staticmethod so this registration will overload on every instance. Which is obviously bad.

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

2013-05-30 Thread Łukasz Langa
On 29 maj 2013, at 04:40, Nick Coghlan wrote: > I expect we will see improved tools for integrating class based > dispatch and generic function dispatch in the future, but we should > *not* try to engineer a solution up front. Doing so would involve too > much guessing about possible use cases, r

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

2013-05-28 Thread Antoine Pitrou
On Wed, 29 May 2013 08:08:14 +0200 Antoine Pitrou wrote: > On Wed, 29 May 2013 12:40:32 +1000 > Nick Coghlan wrote: > > On Wed, May 29, 2013 at 5:41 AM, Russell E. Owen wrote: > > > In article , > > > Łukasz Langa wrote: > > > > > >> Hello, > > >> Since the initial version, several minor chang

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

2013-05-28 Thread Antoine Pitrou
On Wed, 29 May 2013 12:40:32 +1000 Nick Coghlan wrote: > On Wed, May 29, 2013 at 5:41 AM, Russell E. Owen wrote: > > In article , > > Łukasz Langa wrote: > > > >> Hello, > >> Since the initial version, several minor changes have been made to the > >> PEP. The history is visible on hg.python.org

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

2013-05-28 Thread Nick Coghlan
On Wed, May 29, 2013 at 5:41 AM, Russell E. Owen wrote: > In article , > Łukasz Langa 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 AB

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

2013-05-28 Thread Steven D'Aprano
On 29/05/13 07:27, PJ Eby wrote: On Tue, May 28, 2013 at 3:41 PM, Russell E. Owen wrote: 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

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

2013-05-28 Thread PJ Eby
On Tue, May 28, 2013 at 3:41 PM, Russell E. Owen wrote: > 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

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

2013-05-28 Thread Russell E. Owen
A question about the example: how hard would it be to modify the example @fun.register(list) ... to work with other collections? If it is easy, I think it would make a for a much more useful example. -- Russell ___ Python-Dev mailing list Python-Dev@

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

2013-05-28 Thread Russell E. Owen
In article , Łukasz Langa 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 ope

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

2013-05-27 Thread Łukasz Langa
On 27 maj 2013, at 15:31, Łukasz Langa wrote: > This is exactly what I did now. I also exposed ._clear_cache() and the > uncached ._find_impl() if somebody finds it necessary to use it. Both > are left undocumented. For the record, I moved _find_impl out of the closure for easier testability. I

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

2013-05-27 Thread Łukasz Langa
On 26 maj 2013, at 03:37, Nick Coghlan wrote: > On Sun, May 26, 2013 at 9:07 AM, PJ Eby wrote: >> On Sat, May 25, 2013 at 4:16 PM, Łukasz Langa wrote: >>> So, the latest document is live: >>> http://www.python.org/dev/peps/pep-0443/ >>> >>> The code is here: >>> http://hg.python.org/features/p

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

2013-05-27 Thread Łukasz Langa
On 26 maj 2013, at 01:07, PJ Eby wrote: > 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. All suggested changes applied. There are still a couple of ment

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

2013-05-25 Thread Steven D'Aprano
On 26/05/13 09:07, PJ Eby wrote: """ Transforms a function into a single-dispatch generic function. A **generic function** is composed of multiple functions implementing the same operation for different types. Which implementation should be used during a call is determined by the dispatch algori

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

2013-05-25 Thread Nick Coghlan
On Sun, May 26, 2013 at 9:07 AM, PJ Eby wrote: > On Sat, May 25, 2013 at 4:16 PM, Łukasz Langa 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 us

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

2013-05-25 Thread PJ Eby
On Sat, May 25, 2013 at 4:16 PM, Łukasz Langa 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 > > The documentation here: > http://hg.python.org/features/pep-443/file/t

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

2013-05-25 Thread Antoine Pitrou
On Sat, 25 May 2013 22:16:04 +0200 Łukasz Langa wrote: > On 25 maj 2013, at 17:13, Nick Coghlan wrote: > > > So I think I'd prefer flipping this around - you can't provide a > > custom registry mapping, but you *can* get access to a read only view > > of it through a "registry" attribute on the

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

2013-05-25 Thread Łukasz Langa
On 25 maj 2013, at 17:13, Nick Coghlan wrote: > So I think I'd prefer flipping this around - you can't provide a > custom registry mapping, but you *can* get access to a read only view > of it through a "registry" attribute on the generic function. You guys convinced me. Both the PEP and the imp

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

2013-05-25 Thread Nick Coghlan
On Sun, May 26, 2013 at 2:48 AM, PJ Eby wrote: > On Sat, May 25, 2013 at 10:59 AM, Nick Coghlan wrote: >> Given the global nature of the cache invalidation, it may be better as >> a module level abc.get_cache_token() function. > > Well, since the only reason to ever use it is to improve performan

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

2013-05-25 Thread PJ Eby
On Sat, May 25, 2013 at 10:59 AM, Nick Coghlan wrote: > Given the global nature of the cache invalidation, it may be better as > a module level abc.get_cache_token() function. Well, since the only reason to ever use it is to improve performance, it'd be better to expose it as an attribute than as

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

2013-05-25 Thread Nick Coghlan
On Sun, May 26, 2013 at 1:09 AM, Łukasz Langa wrote: > On 25 maj 2013, at 16:59, Nick Coghlan wrote: > > I think I added an issue on the tracker for that somewhere... yup: > http://bugs.python.org/issue16832 > > Given the global nature of the cache invalidation, it may be better as > a module lev

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

2013-05-25 Thread Nick Coghlan
On Sun, May 26, 2013 at 12:53 AM, Łukasz Langa wrote: > On 25 maj 2013, at 16:08, PJ Eby wrote: > >> ISTM there should be some way to get at the raw >> registration info, perhaps by exposing a dictproxy for the registry. > > Is that really useful? Just today Antoine asked about changing > behavio

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

2013-05-25 Thread Łukasz Langa
On 25 maj 2013, at 16:59, Nick Coghlan wrote: > I think I added an issue on the tracker for that somewhere... yup: > http://bugs.python.org/issue16832 > > Given the global nature of the cache invalidation, it may be better as > a module level abc.get_cache_token() function. I assigned myself to

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

2013-05-25 Thread Nick Coghlan
On Sun, May 26, 2013 at 12:08 AM, PJ Eby wrote: > On Sat, May 25, 2013 at 8:08 AM, Łukasz Langa wrote: >> The most important >> change in this version is that I introduced ABC support and completed >> a reference implementation. > > Excellent! A couple of thoughts on the implementation... > > Wh

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

2013-05-25 Thread Łukasz Langa
On 25 maj 2013, at 16:08, PJ Eby wrote: > ISTM there should be some way to get at the raw > registration info, perhaps by exposing a dictproxy for the registry. Is that really useful? Just today Antoine asked about changing behaviour of __subclasses__(), suspecting it isn't used in real world co

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

2013-05-25 Thread PJ Eby
On Sat, May 25, 2013 at 8:08 AM, Łukasz Langa wrote: > The most important > change in this version is that I introduced ABC support and completed > a reference implementation. Excellent! A couple of thoughts on the implementation... While the dispatch() method allows you to look up what impleme

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

2013-05-25 Thread Łukasz Langa
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. PEP: 443