-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
bpo-33967: singledispatch raises TypeError when no positional arguments #8184
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertRaisesRegexp() is deprecated, so this test fails when test_functools is run with -Werror (see #8261).
https://bugs.python.org/issue33967