Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
445f1b35
Commit
445f1b35
authored
Jul 10, 2018
by
Dong-hee Na
Committed by
INADA Naoki
Jul 10, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-33967: Fix singledispatch raised IndexError when no args (GH-8184)
parent
7762e4d3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
0 deletions
+14
-0
Lib/functools.py
Lib/functools.py
+5
-0
Lib/test/test_functools.py
Lib/test/test_functools.py
+7
-0
Misc/NEWS.d/next/Library/2018-07-08-18-49-41.bpo-33967.lhaAez.rst
...S.d/next/Library/2018-07-08-18-49-41.bpo-33967.lhaAez.rst
+2
-0
No files found.
Lib/functools.py
View file @
445f1b35
...
...
@@ -817,8 +817,13 @@ def singledispatch(func):
return
func
def
wrapper
(
*
args
,
**
kw
):
if
not
args
:
raise
TypeError
(
f'
{
funcname
}
requires at least '
'1 positional argument'
)
return
dispatch
(
args
[
0
].
__class__
)(
*
args
,
**
kw
)
funcname
=
getattr
(
func
,
'__name__'
,
'singledispatch function'
)
registry
[
object
]
=
func
wrapper
.
register
=
register
wrapper
.
dispatch
=
dispatch
...
...
Lib/test/test_functools.py
View file @
445f1b35
...
...
@@ -2305,6 +2305,13 @@ class TestSingleDispatch(unittest.TestCase):
))
self
.
assertTrue
(
str
(
exc
.
exception
).
endswith
(
msg_suffix
))
def
test_invalid_positional_argument
(
self
):
@
functools
.
singledispatch
def
f
(
*
args
):
pass
msg
=
'f requires at least 1 positional argument'
with
self
.
assertRaisesRegexp
(
TypeError
,
msg
):
f
()
if
__name__
==
'__main__'
:
unittest
.
main
()
Misc/NEWS.d/next/Library/2018-07-08-18-49-41.bpo-33967.lhaAez.rst
0 → 100644
View file @
445f1b35
functools.singledispatch now raises TypeError instead of IndexError when no
positional arguments are passed.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment