Skip to content
6 changes: 0 additions & 6 deletions Lib/test/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ def setUp(self):
self.o2 = newstyle()
self.n2 = newstyle()

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_index(self):
self.o.ind = -2
self.n.ind = 2
Expand Down Expand Up @@ -140,8 +138,6 @@ def test_repeat(self):
self.assertEqual(self.o * self.seq, self.seq * 3)
self.assertEqual(self.n * self.seq, self.seq * 2)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_wrappers(self):
self.o.ind = 4
self.n.ind = 5
Expand Down Expand Up @@ -169,8 +165,6 @@ def test_error(self):
class ListTestCase(SeqTestCase, unittest.TestCase):
seq = [0,10,20,30,40,50]

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_setdelitem(self):
self.o.ind = -2
self.n.ind = 2
Expand Down
4 changes: 2 additions & 2 deletions derive/src/pyclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ fn generate_class_def(
}

impl ::rustpython_vm::StaticType for #ident {
fn static_cell() -> &'static ::rustpython_common::static_cell::StaticCell<::rustpython_vm::builtins::PyTypeRef> {
::rustpython_common::static_cell! {
fn static_cell() -> &'static ::rustpython_vm::common::static_cell::StaticCell<::rustpython_vm::builtins::PyTypeRef> {
::rustpython_vm::common::static_cell! {
static CELL: ::rustpython_vm::builtins::PyTypeRef;
}
&CELL
Expand Down
154 changes: 154 additions & 0 deletions extra_tests/snippets/builtin_exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import platform
import sys


# Regression to:
# https://github.com/RustPython/RustPython/issues/2779

class MyError(Exception):
pass


e = MyError('message')

try:
raise e from e
except MyError as exc:
# It was a segmentation fault before, will print info to stdout:
sys.excepthook(type(exc), exc, exc.__traceback__)
assert isinstance(exc, MyError)
assert exc.__cause__ is e
assert exc.__context__ is None
else:
assert False, 'exception not raised'

try:
raise ValueError('test') from e
except ValueError as exc:
sys.excepthook(type(exc), exc, exc.__traceback__) # ok, will print two excs
assert isinstance(exc, ValueError)
assert exc.__cause__ is e
assert exc.__context__ is None
else:
assert False, 'exception not raised'


# New case:
# potential recursion on `__context__` field

e = MyError('message')

try:
try:
raise e
except MyError as exc:
raise e
else:
assert False, 'exception not raised'
except MyError as exc:
sys.excepthook(type(exc), exc, exc.__traceback__)
assert exc.__cause__ is None
assert exc.__context__ is None
else:
assert False, 'exception not raised'

e = MyError('message')

try:
try:
raise e
except MyError as exc:
raise exc
else:
assert False, 'exception not raised'
except MyError as exc:
sys.excepthook(type(exc), exc, exc.__traceback__)
assert exc.__cause__ is None
assert exc.__context__ is None
else:
assert False, 'exception not raised'

e = MyError('message')

try:
try:
raise e
except MyError as exc:
raise e from e
else:
assert False, 'exception not raised'
except MyError as exc:
sys.excepthook(type(exc), exc, exc.__traceback__)
assert exc.__cause__ is e
assert exc.__context__ is None
else:
assert False, 'exception not raised'

e = MyError('message')

try:
try:
raise e
except MyError as exc:
raise exc from e
else:
assert False, 'exception not raised'
except MyError as exc:
sys.excepthook(type(exc), exc, exc.__traceback__)
assert exc.__cause__ is e
assert exc.__context__ is None
else:
assert False, 'exception not raised'


# New case:
# two exception in a recursion loop

class SubError(MyError):
pass

e = MyError('message')
d = SubError('sub')


try:
raise e from d
except MyError as exc:
# It was a segmentation fault before, will print info to stdout:
sys.excepthook(type(exc), exc, exc.__traceback__)
assert isinstance(exc, MyError)
assert exc.__cause__ is d
assert exc.__context__ is None
else:
assert False, 'exception not raised'

e = MyError('message')

try:
raise d from e
except SubError as exc:
# It was a segmentation fault before, will print info to stdout:
sys.excepthook(type(exc), exc, exc.__traceback__)
assert isinstance(exc, SubError)
assert exc.__cause__ is e
assert exc.__context__ is None
else:
assert False, 'exception not raised'


# New case:
# explicit `__context__` manipulation.

e = MyError('message')
e.__context__ = e

try:
raise e
except MyError as exc:
# It was a segmentation fault before, will print info to stdout:
if platform.python_implementation() == 'RustPython':
# For some reason `CPython` hangs on this code:
sys.excepthook(type(exc), exc, exc.__traceback__)
assert isinstance(exc, MyError)
assert exc.__cause__ is None
assert exc.__context__ is e
Loading