Title: singledispatchmethod doesn't handle named arguments
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.11, Python 3.10, Python 3.9
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: AlexWaygood, alisson276, lukasz.langa, rhettinger
Priority: normal Keywords:

Created on 2021-11-29 13:15 by alisson276, last changed 2021-11-29 14:17 by AlexWaygood.

Messages (2)
msg407273 - (view) Author: Alisson Oliveira (alisson276) Date: 2021-11-29 13:15
`functools.singledispatchmethod` doesn't handle named arguments. Ex:

from functools import singledispatchmethod

class Test:
    def __init__(self):

    def get(self, filters):
        return 'Not Implemented!'

    def _(self, filters: dict):
        for k, v in filters.items():
            print(k, ' => ' ,  v)

    def _(self, filters: list):
        for f in filters:

if __name__ == '__main__':
    t = Test()
    t.get({'a': 'A'})
    t.get(filters={'a': 'A'})

This will raise an error:
a  =>  A
Traceback (most recent call last):
  File "/Users/alisson.oliveira/Farfetch/Git/blueprints-package/", line 33, in <module>
    t.get(filters={'a': 'A'})
  File "/usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/", line 926, in _method
    method = self.dispatcher.dispatch(args[0].__class__)
IndexError: tuple index out of range

the problem is the lib always assume positional arguments in line 194:
msg407277 - (view) Author: Alex Waygood (AlexWaygood) * (Python triager) Date: 2021-11-29 14:17
This is arguably a duplicate of
Date User Action Args
2021-11-29 14:17:19AlexWaygoodsetnosy: + rhettinger, lukasz.langa, AlexWaygood

messages: + msg407277
versions: + Python 3.11
2021-11-29 13:15:13alisson276create