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
5afa03a7
Commit
5afa03a7
authored
Jul 15, 2011
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
catch nasty exception classes with __new__ that doesn't return a exception (closes #11627)
Patch from Andreas Stührk.
parent
1f0ccfa8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
0 deletions
+19
-0
Lib/test/test_raise.py
Lib/test/test_raise.py
+9
-0
Misc/NEWS
Misc/NEWS
+3
-0
Python/ceval.c
Python/ceval.c
+7
-0
No files found.
Lib/test/test_raise.py
View file @
5afa03a7
...
@@ -121,6 +121,15 @@ class TestRaise(unittest.TestCase):
...
@@ -121,6 +121,15 @@ class TestRaise(unittest.TestCase):
else
:
else
:
self
.
fail
(
"No exception raised"
)
self
.
fail
(
"No exception raised"
)
def
test_new_returns_invalid_instance
(
self
):
# See issue #11627.
class
MyException
(
Exception
):
def
__new__
(
cls
,
*
args
):
return
object
()
with
self
.
assertRaises
(
TypeError
):
raise
MyException
class
TestCause
(
unittest
.
TestCase
):
class
TestCause
(
unittest
.
TestCase
):
def
test_invalid_cause
(
self
):
def
test_invalid_cause
(
self
):
...
...
Misc/NEWS
View file @
5afa03a7
...
@@ -10,6 +10,9 @@ What's New in Python 3.2.2?
...
@@ -10,6 +10,9 @@ What's New in Python 3.2.2?
Core and Builtins
Core and Builtins
-----------------
-----------------
- Issue #11627: Fix segfault when __new__ on a exception returns a non-exception
class.
- Issue #12149: Update the method cache after a type's dictionnary gets
- Issue #12149: Update the method cache after a type's dictionnary gets
cleared by the garbage collector. This fixes a segfault when an instance
cleared by the garbage collector. This fixes a segfault when an instance
and its type get caught in a reference cycle, and the instance's
and its type get caught in a reference cycle, and the instance's
...
...
Python/ceval.c
View file @
5afa03a7
...
@@ -3413,6 +3413,13 @@ do_raise(PyObject *exc, PyObject *cause)
...
@@ -3413,6 +3413,13 @@ do_raise(PyObject *exc, PyObject *cause)
value
=
PyObject_CallObject
(
exc
,
NULL
);
value
=
PyObject_CallObject
(
exc
,
NULL
);
if
(
value
==
NULL
)
if
(
value
==
NULL
)
goto
raise_error
;
goto
raise_error
;
if
(
!
PyExceptionInstance_Check
(
value
))
{
PyErr_Format
(
PyExc_TypeError
,
"calling %R should have returned an instance of "
"BaseException, not %R"
,
type
,
Py_TYPE
(
value
));
goto
raise_error
;
}
}
}
else
if
(
PyExceptionInstance_Check
(
exc
))
{
else
if
(
PyExceptionInstance_Check
(
exc
))
{
value
=
exc
;
value
=
exc
;
...
...
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