You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
functools.singledispatch interacts poorly with methods #76561
I find this quite unintuitive. Essentially, since singledispatch dispatches based solely on a functions first argument, it is useless on methods unless one wraps it and modifies how it uses the internal wrapper function. I believe this should be relatively easy to fix with adding a check of inspect.ismethod and then modifying the number of the checked argument where appropriate.
I'm happy to write a patch if this change is seen as a good idea.
Added Łukasz to the nosy list, as I'd like his +1 before accepting this change (I do still think it's a good idea, for the same reasons we added partialmethod).
Activity
ethanhs commentedon Dec 19, 2017
Consider the following:
I find this quite unintuitive. Essentially, since singledispatch dispatches based solely on a functions first argument, it is useless on methods unless one wraps it and modifies how it uses the internal wrapper function. I believe this should be relatively easy to fix with adding a check of inspect.ismethod and then modifying the number of the checked argument where appropriate.
I'm happy to write a patch if this change is seen as a good idea.
ilevkivskyi commentedon Dec 22, 2017
I have also noticed this problem and I like the idea. It appeared some time ago on python-ideas, but no one has written a patch.
ncoghlan commentedon Mar 29, 2018
Added Łukasz to the nosy list, as I'd like his +1 before accepting this change (I do still think it's a good idea, for the same reasons we added partialmethod).
ambv commentedon Apr 2, 2018
+1
ambv commentedon May 26, 2018
New changeset c651275 by Łukasz Langa (Ethan Smith) in branch 'master':
bpo-32380: Create functools.singledispatchmethod (bpo-6306)
c651275
ethanhs commentedon May 28, 2018
This was fixed, so I think it can be closed.
methane commentedon Mar 27, 2019
New changeset bc284f0 by Inada Naoki in branch 'master':
bpo-32380: add "versionadded: 3.8" to singledispatchmethod (GH-12580)
bc284f0