-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
functools.singledispatch: Misleading exception when calling without arguments #78148
Comments
When I call a function decorated with functools.singledispatch without an argument, I get the following: $ python
Python 3.6.5 (default, Jun 17 2018, 12:13:06)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import functools
>>> @functools.singledispatch
... def f(x):
... pass
...
>>> f()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/functools.py", line 803, in wrapper
return dispatch(args[0].__class__)(*args, **kw)
IndexError: tuple index out of range I would have expected a TypeError along the lines of TypeError: f() missing 1 required positional argument: 'x' |
Can I take a look this issue? |
Signature mismatch should raise TypeError, not IndexError. |
The test added in this change uses the deprecated method assertRaisesRegexp(), so -Werror will cause test_functools to fail. PR 8261 fixes this. |
The purpose of using assertRaisesRegexp() was testing the error message. assertRaises() doesn't do this. Needed to restore the appropriate assertion method, but using a non-deprecated alias: assertRaisesRegex(). |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: