| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
I think this is too much. I think this is enough: if not args:
raise TypeError("singledispatch requires at least 1 positional argument") |
Sorry, something went wrong.
|
True, both f(x=3) and g(*args) can be called with one argument, so shouldn't be rejected. I think @methane's solution does the right thing. |
Sorry, something went wrong.
|
Okay can I update this PR into suggested one? |
Sorry, something went wrong.
|
Updated! Please take a look! |
Sorry, something went wrong.
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.
Sorry, something went wrong.
|
f"{func.__name__} requires at least 1 positional argument" may be better, if we can assume func.__name__ is available always. I believe singledispatch requires positional argument by design, intentionally. |
Sorry, something went wrong.
|
@methane |
Sorry, something went wrong.
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.
Sorry, something went wrong.
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.
Sorry, something went wrong.
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
Sorry, something went wrong.
|
I fixed it |
Sorry, something went wrong.
|
GH-8220 is a backport of this pull request to the 3.7 branch. |
Sorry, something went wrong.
|
GH-8221 is a backport of this pull request to the 3.6 branch. |
Sorry, something went wrong.
| 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).
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
https://bugs.python.org/issue33967