Message308687
Consider the following:
from functools import singledispatch
class Dispatch:
@singledispatch
def foo(self, a):
return a
@foo.register(int)
def _(self, a):
return "int"
@foo.register(str)
def _(self, a):
return "str"
cls = Dispatch()
cls.foo(3) # 3
cls.foo('hm') # 'hm'
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. |
|
Date |
User |
Action |
Args |
2017-12-19 22:23:08 | ethan smith | set | recipients:
+ ethan smith |
2017-12-19 22:23:08 | ethan smith | set | messageid: <1513722188.44.0.213398074469.issue32380@psf.upfronthosting.co.za> |
2017-12-19 22:23:08 | ethan smith | link | issue32380 messages |
2017-12-19 22:23:08 | ethan smith | create | |
|