bpo-33967: singledispatch raises TypeError when no positional arguments#8184
bpo-33967: singledispatch raises TypeError when no positional arguments#8184methane merged 1 commit intopython:masterfrom
Conversation
|
I think this is too much. I think this is enough: if not args:
raise TypeError("singledispatch requires at least 1 positional argument") |
|
True, both |
|
Okay can I update this PR into suggested one? |
|
Updated! Please take a look! |
Lib/test/test_functools.py
Outdated
There was a problem hiding this comment.
Test seems too redundant for now.
TypeError happens always when no positional arguments.
How the generic function defined is not important.
|
I believe singledispatch requires positional argument by design, intentionally. |
|
@methane |
There was a problem hiding this comment.
Error message is not important here. (We won't backport such improvements)
functools.singledispatch now raises TypeError instead of IndexError when no
positional arguments are passed.
|
@methane I've updated news |
Lib/functools.py
Outdated
There was a problem hiding this comment.
func can be not having the __name__ attribute in general case. This PR can break a code which use singledispatch() with custom callables.
There was a problem hiding this comment.
Also this change creates a new reference to func linked to from wrapper. It may be better to keep a reference just to the name. E.g.
funcname = getattr(func, '__name__', 'singledispatch function')
def wrapper(*args, **kw):
# use funcname|
I fixed it |
|
GH-8220 is a backport of this pull request to the 3.7 branch. |
|
GH-8221 is a backport of this pull request to the 3.6 branch. |
| def f(*args): | ||
| pass | ||
| msg = 'f requires at least 1 positional argument' | ||
| with self.assertRaisesRegexp(TypeError, msg): |
There was a problem hiding this comment.
assertRaisesRegexp() is deprecated, so this test fails when test_functools is run with -Werror (see #8261).
https://bugs.python.org/issue33967