Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion 4 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].

### Changed

- Reattach python exception traceback information (#545)

### Fixed

- Fixed secondary PythonEngine.Initialize call, all sensitive static variables now reseted.
Expand Down Expand Up @@ -697,4 +699,4 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
[i131]: https://github.com/pythonnet/pythonnet/issues/131
[p531]: https://github.com/pythonnet/pythonnet/pull/531
[i755]: https://github.com/pythonnet/pythonnet/pull/755
[p534]: https://github.com/pythonnet/pythonnet/pull/534
[p534]: https://github.com/pythonnet/pythonnet/pull/534
5 changes: 4 additions & 1 deletion 5 src/runtime/exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,10 @@ public static void SetError(Exception e)
var pe = e as PythonException;
if (pe != null)
{
Runtime.PyErr_SetObject(pe.PyType, pe.PyValue);
Runtime.XIncref(pe.PyType);
Runtime.XIncref(pe.PyValue);
Runtime.XIncref(pe.PyTB);
Runtime.PyErr_Restore(pe.PyType, pe.PyValue, pe.PyTB);
return;
}

Expand Down
33 changes: 33 additions & 0 deletions 33 src/tests/test_subclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,39 @@ def test_derived_class():
assert id(x) == id(ob)


def test_derived_traceback():
"""Test python exception traceback in class derived from managed base"""
class DerivedClass(SubClassTest):
__namespace__ = "Python.Test.traceback"

def foo(self):
print (xyzname)
return None

import sys,traceback
ob = DerivedClass()

# direct call
try:
ob.foo()
assert False
except:
e = sys.exc_info()
assert "xyzname" in str(e[1])
location = traceback.extract_tb(e[2])[-1]
assert location[2] == "foo"

# call through managed code
try:
FunctionsTest.test_foo(ob)
assert False
except:
e = sys.exc_info()
assert "xyzname" in str(e[1])
location = traceback.extract_tb(e[2])[-1]
assert location[2] == "foo"


def test_create_instance():
"""Test derived instances can be created from managed code"""
DerivedClass = derived_class_fixture(test_create_instance.__name__)
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.