This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: functools.singledispatch: Misleading exception when calling without arguments
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: ZackerySpytz, corona10, doerwalter, methane, miss-islington, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2018-06-26 11:57 by doerwalter, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 8184 merged corona10, 2018-07-08 09:51
PR 8220 merged miss-islington, 2018-07-10 07:27
PR 8221 merged miss-islington, 2018-07-10 07:28
PR 8261 merged ZackerySpytz, 2018-07-12 02:09
PR 8295 merged miss-islington, 2018-07-16 09:12
PR 8296 merged miss-islington, 2018-07-16 09:13
PR 8306 merged methane, 2018-07-16 23:59
PR 8306 merged methane, 2018-07-16 23:59
PR 8308 merged miss-islington, 2018-07-17 04:45
PR 8309 merged miss-islington, 2018-07-17 04:45
Messages (14)
msg320485 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) Date: 2018-06-26 11:57
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'
msg321259 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2018-07-08 06:26
@doerwalter

Can I take a look this issue?
msg321313 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2018-07-09 12:17
Signature mismatch should raise TypeError, not IndexError.
I think this should be backported to 3.6 and 3.7.
msg321359 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2018-07-10 07:26
New changeset 445f1b35ce8461268438c8a6b327ddc764287e05 by INADA Naoki (Dong-hee Na) in branch 'master':
bpo-33967: Fix singledispatch raised IndexError when no args (GH-8184)
https://github.com/python/cpython/commit/445f1b35ce8461268438c8a6b327ddc764287e05
msg321363 - (view) Author: miss-islington (miss-islington) Date: 2018-07-10 07:49
New changeset df9f633f94e97fc43e0235cb2be076491ea7f67f by Miss Islington (bot) in branch '3.7':
bpo-33967: Fix singledispatch raised IndexError when no args (GH-8184)
https://github.com/python/cpython/commit/df9f633f94e97fc43e0235cb2be076491ea7f67f
msg321365 - (view) Author: miss-islington (miss-islington) Date: 2018-07-10 08:00
New changeset 6ceab46a602c6653356d67d7479391fba0b35697 by Miss Islington (bot) in branch '3.6':
bpo-33967: Fix singledispatch raised IndexError when no args (GH-8184)
https://github.com/python/cpython/commit/6ceab46a602c6653356d67d7479391fba0b35697
msg321512 - (view) Author: Zackery Spytz (ZackerySpytz) * (Python triager) Date: 2018-07-12 02:53
The test added in this change uses the deprecated method assertRaisesRegexp(), so -Werror will cause test_functools to fail. PR 8261 fixes this.
msg321514 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2018-07-12 03:57
New changeset 9e9b2c32a34594e901b5b9a03c561a2a2bf63ece by INADA Naoki (Zackery Spytz) in branch 'master':
bpo-33967: Remove use of deprecated assertRaisesRegexp() (GH-8261)
https://github.com/python/cpython/commit/9e9b2c32a34594e901b5b9a03c561a2a2bf63ece
msg321725 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-07-16 09:26
New changeset 336c9539a90e0f5df5bcc5b444b8400a58820583 by Victor Stinner (Miss Islington (bot)) in branch '3.6':
bpo-33967: Remove use of deprecated assertRaisesRegexp() (GH-8261) (GH-8295)
https://github.com/python/cpython/commit/336c9539a90e0f5df5bcc5b444b8400a58820583
msg321727 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-07-16 09:40
New changeset 0a820a203032e3b1b9413afba45acd8f79f27f81 by Victor Stinner (Miss Islington (bot)) in branch '3.7':
bpo-33967: Remove use of deprecated assertRaisesRegexp() (GH-8261) (GH-8296)
https://github.com/python/cpython/commit/0a820a203032e3b1b9413afba45acd8f79f27f81
msg321743 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-07-16 17:02
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().
msg321789 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2018-07-17 04:44
New changeset 56d8f57b83a37b05a6f2fbc3e141bbc1ba6cb3a2 by INADA Naoki in branch 'master':
bpo-33967: Fix wrong use of assertRaises (GH-8306)
https://github.com/python/cpython/commit/56d8f57b83a37b05a6f2fbc3e141bbc1ba6cb3a2
msg321792 - (view) Author: miss-islington (miss-islington) Date: 2018-07-17 05:18
New changeset 892df9d15aae08d4033faeb34698e3c550c85854 by Miss Islington (bot) in branch '3.7':
bpo-33967: Fix wrong use of assertRaises (GH-8306)
https://github.com/python/cpython/commit/892df9d15aae08d4033faeb34698e3c550c85854
msg321794 - (view) Author: miss-islington (miss-islington) Date: 2018-07-17 05:38
New changeset 8b5d191386350d28a0f20283dcb366cf50f82b97 by Miss Islington (bot) in branch '3.6':
bpo-33967: Fix wrong use of assertRaises (GH-8306)
https://github.com/python/cpython/commit/8b5d191386350d28a0f20283dcb366cf50f82b97
History
Date User Action Args
2022-04-11 14:59:02adminsetgithub: 78148
2018-07-17 06:20:39methanesetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-07-17 05:38:32miss-islingtonsetmessages: + msg321794
2018-07-17 05:18:59miss-islingtonsetmessages: + msg321792
2018-07-17 04:45:59miss-islingtonsetpull_requests: + pull_request7844
2018-07-17 04:45:06miss-islingtonsetpull_requests: + pull_request7843
2018-07-17 04:44:50methanesetmessages: + msg321789
2018-07-16 23:59:27methanesetstage: needs patch -> patch review
pull_requests: + pull_request7841
2018-07-16 23:59:24methanesetstage: needs patch -> needs patch
pull_requests: + pull_request7840
2018-07-16 17:02:10serhiy.storchakasetstatus: closed -> open

nosy: + serhiy.storchaka
messages: + msg321743

resolution: fixed -> (no value)
stage: resolved -> needs patch
2018-07-16 09:40:15vstinnersetmessages: + msg321727
2018-07-16 09:26:52vstinnersetnosy: + vstinner
messages: + msg321725
2018-07-16 09:13:29miss-islingtonsetpull_requests: + pull_request7830
2018-07-16 09:12:18miss-islingtonsetpull_requests: + pull_request7829
2018-07-12 03:57:08methanesetmessages: + msg321514
2018-07-12 02:53:43ZackerySpytzsetnosy: + ZackerySpytz
messages: + msg321512
2018-07-12 02:09:16ZackerySpytzsetpull_requests: + pull_request7794
2018-07-10 08:00:43miss-islingtonsetmessages: + msg321365
2018-07-10 07:50:01methanesetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-07-10 07:49:02miss-islingtonsetnosy: + miss-islington
messages: + msg321363
2018-07-10 07:28:47miss-islingtonsetpull_requests: + pull_request7759
2018-07-10 07:27:54miss-islingtonsetpull_requests: + pull_request7758
2018-07-10 07:26:40methanesetmessages: + msg321359
2018-07-09 12:17:20methanesetnosy: + methane

messages: + msg321313
versions: + Python 3.7, Python 3.8
2018-07-08 09:51:59corona10setkeywords: + patch
stage: patch review
pull_requests: + pull_request7739
2018-07-08 06:26:36corona10setnosy: + corona10
messages: + msg321259
2018-06-26 11:57:10doerwaltercreate