New submission from Ethan Smith <et...@ethanhs.me>: 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. ---------- components: Library (Lib) messages: 308687 nosy: Ethan Smith priority: normal severity: normal status: open title: functools.singledispatch interacts poorly with methods type: behavior versions: Python 3.6 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32380> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com