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
0bb165ec
Commit
0bb165ec
authored
Jan 31, 2016
by
Martin Panter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #4806: Avoid masking TypeError when *-unpacking a generator
Based on patch by Hagen Fürstenau.
parent
414f8b93
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
7 deletions
+24
-7
Lib/test/test_extcall.py
Lib/test/test_extcall.py
+16
-5
Misc/NEWS
Misc/NEWS
+4
-0
Python/ceval.c
Python/ceval.c
+4
-2
No files found.
Lib/test/test_extcall.py
View file @
0bb165ec
...
@@ -93,7 +93,7 @@ Verify clearing of SF bug #733667
...
@@ -93,7 +93,7 @@ Verify clearing of SF bug #733667
>>> g(*Nothing())
>>> g(*Nothing())
Traceback (most recent call last):
Traceback (most recent call last):
...
...
TypeError: g() argument after * must be a
sequenc
e, not instance
TypeError: g() argument after * must be a
n iterabl
e, not instance
>>> class Nothing:
>>> class Nothing:
... def __len__(self): return 5
... def __len__(self): return 5
...
@@ -102,7 +102,7 @@ Verify clearing of SF bug #733667
...
@@ -102,7 +102,7 @@ Verify clearing of SF bug #733667
>>> g(*Nothing())
>>> g(*Nothing())
Traceback (most recent call last):
Traceback (most recent call last):
...
...
TypeError: g() argument after * must be a
sequenc
e, not instance
TypeError: g() argument after * must be a
n iterabl
e, not instance
>>> class Nothing():
>>> class Nothing():
... def __len__(self): return 5
... def __len__(self): return 5
...
@@ -128,6 +128,17 @@ Verify clearing of SF bug #733667
...
@@ -128,6 +128,17 @@ Verify clearing of SF bug #733667
>>> g(*Nothing())
>>> g(*Nothing())
0 (1, 2, 3) {}
0 (1, 2, 3) {}
Check for issue #4806: Does a TypeError in a generator get propagated with the
right error message?
>>> def broken(): raise TypeError("myerror")
...
>>> g(*(broken() for i in range(1)))
Traceback (most recent call last):
...
TypeError: myerror
Make sure that the function doesn't stomp the dictionary
Make sure that the function doesn't stomp the dictionary
>>> d = {'a': 1, 'b': 2, 'c': 3}
>>> d = {'a': 1, 'b': 2, 'c': 3}
...
@@ -167,17 +178,17 @@ What about willful misconduct?
...
@@ -167,17 +178,17 @@ What about willful misconduct?
>>> h(*h)
>>> h(*h)
Traceback (most recent call last):
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)
>>> dir(*h)
Traceback (most recent call last):
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)
>>> None(*h)
Traceback (most recent call last):
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
not function
>>> h(**h)
>>> h(**h)
...
...
Misc/NEWS
View file @
0bb165ec
...
@@ -10,6 +10,10 @@ What's New in Python 2.7.12?
...
@@ -10,6 +10,10 @@ What's New in Python 2.7.12?
Core and Builtins
Core and Builtins
-----------------
-----------------
- Issue #4806: Avoid masking the original TypeError exception when using star
(*) unpacking and the exception was raised from a generator. Based on
patch by Hagen Fürstenau.
- Issue #26659: Make the builtin slice type support cycle collection.
- Issue #26659: Make the builtin slice type support cycle collection.
- Issue #26718: super.__init__ no longer leaks memory if called multiple times.
- Issue #26718: super.__init__ no longer leaks memory if called multiple times.
...
...
Python/ceval.c
View file @
0bb165ec
...
@@ -4615,10 +4615,12 @@ ext_do_call(PyObject *func, PyObject ***pp_stack, int flags, int na, int nk)
...
@@ -4615,10 +4615,12 @@ ext_do_call(PyObject *func, PyObject ***pp_stack, int flags, int na, int nk)
PyObject
*
t
=
NULL
;
PyObject
*
t
=
NULL
;
t
=
PySequence_Tuple
(
stararg
);
t
=
PySequence_Tuple
(
stararg
);
if
(
t
==
NULL
)
{
if
(
t
==
NULL
)
{
if
(
PyErr_ExceptionMatches
(
PyExc_TypeError
))
{
if
(
PyErr_ExceptionMatches
(
PyExc_TypeError
)
&&
/* Don't mask TypeError raised from a generator */
!
PyGen_Check
(
stararg
))
{
PyErr_Format
(
PyExc_TypeError
,
PyErr_Format
(
PyExc_TypeError
,
"%.200s%.200s argument after * "
"%.200s%.200s argument after * "
"must be a
sequenc
e, not %200s"
,
"must be a
n iterabl
e, not %200s"
,
PyEval_GetFuncName
(
func
),
PyEval_GetFuncName
(
func
),
PyEval_GetFuncDesc
(
func
),
PyEval_GetFuncDesc
(
func
),
stararg
->
ob_type
->
tp_name
);
stararg
->
ob_type
->
tp_name
);
...
...
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