File tree 3 files changed +40
-2
lines changed
3 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,8 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
25
25
26
26
### Changed
27
27
28
+ - Reattach python exception traceback information (#545 )
29
+
28
30
### Fixed
29
31
30
32
- Fixed secondary PythonEngine.Initialize call, all sensitive static variables now reseted.
@@ -697,4 +699,4 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
697
699
[ i131 ] : https://github.com/pythonnet/pythonnet/issues/131
698
700
[ p531 ] : https://github.com/pythonnet/pythonnet/pull/531
699
701
[ i755 ] : https://github.com/pythonnet/pythonnet/pull/755
700
- [ p534 ] : https://github.com/pythonnet/pythonnet/pull/534
702
+ [ p534 ] : https://github.com/pythonnet/pythonnet/pull/534
Original file line number Diff line number Diff line change @@ -256,7 +256,10 @@ public static void SetError(Exception e)
256
256
var pe = e as PythonException ;
257
257
if ( pe != null )
258
258
{
259
- Runtime . PyErr_SetObject ( pe . PyType , pe . PyValue ) ;
259
+ Runtime . XIncref ( pe . PyType ) ;
260
+ Runtime . XIncref ( pe . PyValue ) ;
261
+ Runtime . XIncref ( pe . PyTB ) ;
262
+ Runtime . PyErr_Restore ( pe . PyType , pe . PyValue , pe . PyTB ) ;
260
263
return ;
261
264
}
262
265
Original file line number Diff line number Diff line change @@ -128,6 +128,39 @@ def test_derived_class():
128
128
assert id (x ) == id (ob )
129
129
130
130
131
+ def test_derived_traceback ():
132
+ """Test python exception traceback in class derived from managed base"""
133
+ class DerivedClass (SubClassTest ):
134
+ __namespace__ = "Python.Test.traceback"
135
+
136
+ def foo (self ):
137
+ print (xyzname )
138
+ return None
139
+
140
+ import sys ,traceback
141
+ ob = DerivedClass ()
142
+
143
+ # direct call
144
+ try :
145
+ ob .foo ()
146
+ assert False
147
+ except :
148
+ e = sys .exc_info ()
149
+ assert "xyzname" in str (e [1 ])
150
+ location = traceback .extract_tb (e [2 ])[- 1 ]
151
+ assert location [2 ] == "foo"
152
+
153
+ # call through managed code
154
+ try :
155
+ FunctionsTest .test_foo (ob )
156
+ assert False
157
+ except :
158
+ e = sys .exc_info ()
159
+ assert "xyzname" in str (e [1 ])
160
+ location = traceback .extract_tb (e [2 ])[- 1 ]
161
+ assert location [2 ] == "foo"
162
+
163
+
131
164
def test_create_instance ():
132
165
"""Test derived instances can be created from managed code"""
133
166
DerivedClass = derived_class_fixture (test_create_instance .__name__ )
You can’t perform that action at this time.
0 commit comments