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
b5944220
Commit
b5944220
authored
Jan 31, 2016
by
Martin Panter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #4806: Avoid masking original TypeError in call with * unpacking
Based on patch by Hagen Fürstenau and Daniel Urban.
parent
4c5ad945
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
13 deletions
+58
-13
Lib/test/test_extcall.py
Lib/test/test_extcall.py
+44
-5
Misc/NEWS
Misc/NEWS
+4
-0
Python/ceval.c
Python/ceval.c
+10
-8
No files found.
Lib/test/test_extcall.py
View file @
b5944220
...
...
@@ -114,7 +114,7 @@ Verify clearing of SF bug #733667
>>> g(*Nothing())
Traceback (most recent call last):
...
TypeError: g() argument after * must be a
sequenc
e, not Nothing
TypeError: g() argument after * must be a
n iterabl
e, not Nothing
>>> class Nothing:
... def __len__(self): return 5
...
...
@@ -123,7 +123,7 @@ Verify clearing of SF bug #733667
>>> g(*Nothing())
Traceback (most recent call last):
...
TypeError: g() argument after * must be a
sequenc
e, not Nothing
TypeError: g() argument after * must be a
n iterabl
e, not Nothing
>>> class Nothing():
... def __len__(self): return 5
...
...
@@ -149,6 +149,45 @@ Verify clearing of SF bug #733667
>>> g(*Nothing())
0 (1, 2, 3) {}
Check for issue #4806: Does a TypeError in a generator get propagated with the
right error message? (Also check with other iterables.)
>>> def broken(): raise TypeError("myerror")
...
>>> g(*(broken() for i in range(1)))
Traceback (most recent call last):
...
TypeError: myerror
>>> class BrokenIterable1:
... def __iter__(self):
... raise TypeError('myerror')
...
>>> g(*BrokenIterable1())
Traceback (most recent call last):
...
TypeError: myerror
>>> class BrokenIterable2:
... def __iter__(self):
... yield 0
... raise TypeError('myerror')
...
>>> g(*BrokenIterable2())
Traceback (most recent call last):
...
TypeError: myerror
>>> class BrokenSequence:
... def __getitem__(self, idx):
... raise TypeError('myerror')
...
>>> g(*BrokenSequence())
Traceback (most recent call last):
...
TypeError: myerror
Make sure that the function doesn't stomp the dictionary
>>> d = {'a': 1, 'b': 2, 'c': 3}
...
...
@@ -188,17 +227,17 @@ What about willful misconduct?
>>> h(*h)
Traceback (most recent call last):
...
TypeError: h() argument after * must be a
sequenc
e, not function
TypeError: h() argument after * must be a
n iterabl
e, not function
>>> dir(*h)
Traceback (most recent call last):
...
TypeError: dir() argument after * must be a
sequenc
e, not function
TypeError: dir() argument after * must be a
n iterabl
e, not function
>>> None(*h)
Traceback (most recent call last):
...
TypeError: NoneType object argument after * must be a
sequenc
e,
\
TypeError: NoneType object argument after * must be a
n iterabl
e,
\
not function
>>> h(**h)
...
...
Misc/NEWS
View file @
b5944220
...
...
@@ -10,6 +10,10 @@ Release date: tba
Core and Builtins
-----------------
- Issue #4806: Avoid masking the original TypeError exception when using star
(*) unpacking in function calls. Based on patch by Hagen Fürstenau and
Daniel Urban.
- Issue #26154: Add a new private _PyThreadState_UncheckedGet() function to get
the current Python thread state, but don'
t
issue
a
fatal
error
if
it
is
NULL
.
This
new
function
must
be
used
instead
of
accessing
directly
the
...
...
Python/ceval.c
View file @
b5944220
...
...
@@ -4935,16 +4935,18 @@ ext_do_call(PyObject *func, PyObject ***pp_stack, int flags, int na, int nk)
stararg
=
EXT_POP
(
*
pp_stack
);
if
(
!
PyTuple_Check
(
stararg
))
{
PyObject
*
t
=
NULL
;
if
(
Py_TYPE
(
stararg
)
->
tp_iter
==
NULL
&&
!
PySequence_Check
(
stararg
))
{
PyErr_Format
(
PyExc_TypeError
,
"%.200s%.200s argument after * "
"must be an iterable, not %.200s"
,
PyEval_GetFuncName
(
func
),
PyEval_GetFuncDesc
(
func
),
stararg
->
ob_type
->
tp_name
);
goto
ext_call_fail
;
}
t
=
PySequence_Tuple
(
stararg
);
if
(
t
==
NULL
)
{
if
(
PyErr_ExceptionMatches
(
PyExc_TypeError
))
{
PyErr_Format
(
PyExc_TypeError
,
"%.200s%.200s argument after * "
"must be a sequence, not %.200s"
,
PyEval_GetFuncName
(
func
),
PyEval_GetFuncDesc
(
func
),
stararg
->
ob_type
->
tp_name
);
}
goto
ext_call_fail
;
}
Py_DECREF
(
stararg
);
...
...
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