[New-bugs-announce] [issue45926] singledispatchmethod doesn't handle named arguments
Alisson Oliveira
report at bugs.python.org
Mon Nov 29 08:15:13 EST 2021
New submission from Alisson Oliveira <a2r7o6 at gmail.com>:
`functools.singledispatchmethod` doesn't handle named arguments. Ex:
```python
from functools import singledispatchmethod
class Test:
def __init__(self):
...
@singledispatchmethod
def get(self, filters):
return 'Not Implemented!'
@get.register
def _(self, filters: dict):
for k, v in filters.items():
print(k, ' => ' , v)
@get.register
def _(self, filters: list):
for f in filters:
print(f)
if __name__ == '__main__':
t = Test()
t.get({'a': 'A'})
t.get(['a'])
t.get(filters={'a': 'A'})
```
This will raise an error:
```
a => A
a
Traceback (most recent call last):
File "/Users/alisson.oliveira/Farfetch/Git/blueprints-package/main.py", line 33, in <module>
t.get(filters={'a': 'A'})
File "/usr/local/Cellar/python at 3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/functools.py", 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: https://github.com/python/cpython/blob/main/Lib/functools.py#L914
----------
components: Library (Lib)
messages: 407273
nosy: alisson276
priority: normal
severity: normal
status: open
title: singledispatchmethod doesn't handle named arguments
type: behavior
versions: Python 3.10, Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45926>
_______________________________________
More information about the New-bugs-announce
mailing list