Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f097f17

Browse files
committed
Merge #17413: make sure settrace funcs get passed exception instances for 'value'.
Patch by Ingrid Cheung and Brendan McLoughlin.
2 parents 24aa159 + 3583761 commit f097f17

4 files changed

Lines changed: 30 additions & 0 deletions

File tree

Lib/test/test_sys_settrace.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,29 @@ def g(frame, why, extra):
458458
self.fail("exception not propagated")
459459

460460

461+
def test_exception_arguments(self):
462+
def f():
463+
x = 0
464+
# this should raise an error
465+
x.no_such_attr
466+
def g(frame, event, arg):
467+
if (event == 'exception'):
468+
type, exception, trace = arg
469+
self.assertIsInstance(exception, Exception)
470+
return g
471+
472+
existing = sys.gettrace()
473+
try:
474+
sys.settrace(g)
475+
try:
476+
f()
477+
except AttributeError:
478+
# this is expected
479+
pass
480+
finally:
481+
sys.settrace(existing)
482+
483+
461484
# 'Jump' tests: assigning to frame.f_lineno within a trace function
462485
# moves the execution position - it's how debuggers implement a Jump
463486
# command (aka. "Set next statement").

Misc/ACKS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ David Chaum
211211
Nicolas Chauvat
212212
Jerry Chen
213213
Michael Chermside
214+
Ingrid Cheung
214215
Albert Chin-A-Young
215216
Adal Chiriliuc
216217
Matt Chisholm
@@ -802,6 +803,7 @@ Chris McDonough
802803
Greg McFarlane
803804
Alan McIntyre
804805
Michael McLay
806+
Brendan McLoughlin
805807
Mark Mc Mahon
806808
Gordon McMillan
807809
Andrew McNamara

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ What's New in Python 3.4.0 Alpha 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #17413: sys.settrace callbacks were being passed a string instead of an
14+
exception instance for the 'value' element of the arg tuple if the exception
15+
originated from C code; now an exception instance is always provided.
16+
1317
- Issue #17782: Fix undefined behaviour on platforms where
1418
``struct timespec``'s "tv_nsec" member is not a C long.
1519

Python/ceval.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3793,6 +3793,7 @@ call_exc_trace(Py_tracefunc func, PyObject *self, PyFrameObject *f)
37933793
value = Py_None;
37943794
Py_INCREF(value);
37953795
}
3796+
PyErr_NormalizeException(&type, &value, &traceback);
37963797
arg = PyTuple_Pack(3, type, value, traceback);
37973798
if (arg == NULL) {
37983799
PyErr_Restore(type, value, traceback);

0 commit comments

Comments
 (0)