[Python-Dev] Supporting functools.singledispatch with classes. (original) (raw)
Ethan Smith ethan at ethanhs.me
Wed Dec 27 13:22:38 EST 2017
- Previous message (by thread): [Python-Dev] Supporting functools.singledispatch with classes.
- Next message (by thread): [Python-Dev] Supporting functools.singledispatch with classes.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Okay, if there is no further feedback, I will work on a singledispatchmethod decorator like partialmethod.
For the future perhaps, would it not be possible to tell that the passed argument is a descriptor/function and dispatch to the correct implementation, thus not needing two functions for essentially the same thing?
It seems more straightforward to make the implementation a bit more complex to provide a single, simple API to users.
Cheers,
Ethan
On Tue, Dec 26, 2017 at 3:29 PM, Ivan Levkivskyi <levkivskyi at gmail.com> wrote:
On 26 December 2017 at 01:41, Nick Coghlan <ncoghlan at gmail.com> wrote:
On 25 December 2017 at 12:32, Ethan Smith <ethan at ethanhs.me> wrote: > So at the moment, I don't think it is possible to implement singledispatch > on classmethod or staticmethod decorated functions.
I've posted this to the PR, but adding it here as well: I think this is a situation very similar to the case with functools.partialmethod, where you're going to need to write a separate functools.singledispatchmethod class that's aware of the descriptor protocol, rather than trying to add the functionality directly to functools.singledispatch. I agree with Nick here. Adding a separate decorator looks like the right approach, especially taking into account the precedent of @partialmethod. -- Ivan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20171227/91412128/attachment.html>
- Previous message (by thread): [Python-Dev] Supporting functools.singledispatch with classes.
- Next message (by thread): [Python-Dev] Supporting functools.singledispatch with classes.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]