Uh oh!
There was an error while loading. Please reload this page.
bpo-33967: singledispatch raises TypeError when no positional arguments - #8184
Conversation
I think this is too much. I think this is enough: ifnotargs:
raiseTypeError("singledispatch requires at least 1 positional argument") |
doerwalter
commented
Jul 9, 2018
True, both |
Okay can I update this PR into suggested one? |
corona10
commented
Jul 9, 2018
Updated! Please take a look! |
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.
methane
commented
Jul 9, 2018
I believe singledispatch requires positional argument by design, intentionally. |
corona10
commented
Jul 9, 2018
@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.
corona10
commented
Jul 9, 2018
@methane I've updated news |
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')
defwrapper(*args, **kw):
# use funcnamecorona10
commented
Jul 10, 2018
I fixed it |
miss-islington
commented
Jul 10, 2018
bedevere-bot
commented
Jul 10, 2018
GH-8220 is a backport of this pull request to the 3.7 branch. |
bedevere-bot
commented
Jul 10, 2018
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