Skip to content

Commit 6f8360a

Browse files
committed
sys.exception
1 parent 6ca4685 commit 6f8360a

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

Lib/test/test_sys.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ class ActiveExceptionTests(unittest.TestCase):
7575
def test_exc_info_no_exception(self):
7676
self.assertEqual(sys.exc_info(), (None, None, None))
7777

78-
# TODO: RUSTPYTHON; AttributeError: module 'sys' has no attribute 'exception'
79-
@unittest.expectedFailure
8078
def test_sys_exception_no_exception(self):
8179
self.assertEqual(sys.exception(), None)
8280

@@ -110,8 +108,6 @@ def f():
110108
self.assertIs(exc_info[1], e)
111109
self.assertIs(exc_info[2], e.__traceback__)
112110

113-
# TODO: RUSTPYTHON; AttributeError: module 'sys' has no attribute 'exception'
114-
@unittest.expectedFailure
115111
def test_sys_exception_with_exception_instance(self):
116112
def f():
117113
raise ValueError(42)
@@ -125,8 +121,6 @@ def f():
125121
self.assertIsInstance(e, ValueError)
126122
self.assertIs(exc, e)
127123

128-
# TODO: RUSTPYTHON; AttributeError: module 'sys' has no attribute 'exception'
129-
@unittest.expectedFailure
130124
def test_sys_exception_with_exception_type(self):
131125
def f():
132126
raise ValueError

vm/src/stdlib/sys.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ pub(crate) use sys::{UnraisableHookArgs, __module_def, DOC, MAXSIZE, MULTIARCH};
55
#[pymodule]
66
mod sys {
77
use crate::{
8-
builtins::{PyDictRef, PyNamespace, PyStr, PyStrRef, PyTupleRef, PyTypeRef},
8+
builtins::{
9+
PyBaseExceptionRef, PyDictRef, PyNamespace, PyStr, PyStrRef, PyTupleRef, PyTypeRef,
10+
},
911
common::{
1012
ascii,
1113
hash::{PyHash, PyUHash},
@@ -309,6 +311,11 @@ mod sys {
309311
Err(vm.new_exception(vm.ctx.exceptions.system_exit.to_owned(), vec![code]))
310312
}
311313

314+
#[pyfunction]
315+
fn exception(vm: &VirtualMachine) -> Option<PyBaseExceptionRef> {
316+
vm.topmost_exception()
317+
}
318+
312319
#[pyfunction(name = "__displayhook__")]
313320
#[pyfunction]
314321
fn displayhook(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {

0 commit comments

Comments
 (0)