FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-33967: singledispatch raises TypeError when no positional arguments by corona10 · Pull Request #8184 · python/cpython · GitHub

/ cpython Public

bpo-33967: singledispatch raises TypeError when no positional arguments - #8184

Merged
methane merged 1 commit into
python:masterfrom
corona10:bpo-33967
Jul 10, 2018
Merged

bpo-33967: singledispatch raises TypeError when no positional arguments#8184
methane merged 1 commit into
python:masterfrom
corona10:bpo-33967

Conversation

corona10 commented Jul 8, 2018
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Member

methane commented Jul 9, 2018
edited
Loading

Copy link
Copy Markdown
Member

I think this is too much.

I think this is enough:

if not args:
    raise TypeError("singledispatch requires at least 1 positional argument")

methane requested a review from ambv July 9, 2018 09:15

Copy link
Copy Markdown
Contributor

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.

corona10 commented Jul 9, 2018
edited
Loading

Copy link
Copy Markdown
Member Author

Okay can I update this PR into suggested one?

corona10 commented Jul 9, 2018

Copy link
Copy Markdown
Member Author

@doerwalter @methane

Updated! Please take a look!

Comment thread Lib/test/test_functools.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Member

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.
But I want @ambv review before merge.

corona10 commented Jul 9, 2018

Copy link
Copy Markdown
Member Author

@methane
Thanks for the quick review.
Updated!
One more thing, we need to add tags needs backport to 3.7 / 3.6.

methane changed the title bpo-33967: Improve functools.singledispatch exception messages bpo-33967: singledispatch raises TypeError when no positional arguments Jul 9, 2018

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 added type-bug An unexpected behavior, bug, or error needs backport to 3.6 labels Jul 9, 2018

corona10 commented Jul 9, 2018

Copy link
Copy Markdown
Member Author

@methane I've updated news

Comment thread Lib/functools.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

func can be not having the __name__ attribute in general case. This PR can break a code which use singledispatch() with custom callables.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Member Author

I fixed it

methane merged commit 445f1b3 into python:master Jul 10, 2018

Copy link
Copy Markdown
Contributor

Thanks @corona10 for the PR, and @methane for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7.
🐍🍒⛏🤖

Copy link
Copy Markdown

GH-8220 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 10, 2018
…H-8184)

(cherry picked from commit 445f1b3)

Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>

Copy link
Copy Markdown

GH-8221 is a backport of this pull request to the 3.6 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 10, 2018
…H-8184)

(cherry picked from commit 445f1b3)

Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
miss-islington added a commit that referenced this pull request Jul 10, 2018
(cherry picked from commit 445f1b3)

Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
miss-islington added a commit that referenced this pull request Jul 10, 2018
(cherry picked from commit 445f1b3)

Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
def f(*args):
pass
msg = 'f requires at least 1 positional argument'
with self.assertRaisesRegexp(TypeError, msg):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

assertRaisesRegexp() is deprecated, so this test fails when test_functools is run with -Werror (see #8261).

corona10 deleted the bpo-33967 branch November 22, 2018 11:21
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants


Back | FazBrowse Home | New Git URL