Skip to content

Commit 44d66dc

Browse files
committed
Fix SyntaxError
1 parent a186a5a commit 44d66dc

3 files changed

Lines changed: 38 additions & 12 deletions

File tree

‎Lib/test/test_exceptions.py‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,6 @@ def test_windows_message(self):
425425
with self.assertRaisesRegex(OSError, 'Windows Error 0x%x' % code):
426426
ctypes.pythonapi.PyErr_SetFromWindowsErr(code)
427427

428-
# TODO: RUSTPYTHON
429-
@unittest.expectedFailure
430428
def testAttributes(self):
431429
# test that exception attributes are happy
432430

@@ -2567,8 +2565,6 @@ def test_non_utf8(self):
25672565
finally:
25682566
unlink(TESTFN)
25692567

2570-
# TODO: RUSTPYTHON
2571-
@unittest.expectedFailure
25722568
def test_attributes_new_constructor(self):
25732569
args = ("bad.py", 1, 2, "abcdefg", 1, 100)
25742570
the_exception = SyntaxError("bad bad", args)
@@ -2581,8 +2577,6 @@ def test_attributes_new_constructor(self):
25812577
self.assertEqual(error, the_exception.text)
25822578
self.assertEqual("bad bad", the_exception.msg)
25832579

2584-
# TODO: RUSTPYTHON
2585-
@unittest.expectedFailure
25862580
def test_attributes_old_constructor(self):
25872581
args = ("bad.py", 1, 2, "abcdefg")
25882582
the_exception = SyntaxError("bad bad", args)

‎Lib/test/test_traceback.py‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ def test_caret(self):
9393
self.assertEqual(err[1].find("("), err[2].find("^")) # in the right place
9494
self.assertEqual(err[2].count("^"), 1)
9595

96-
# TODO: RUSTPYTHON
97-
@unittest.expectedFailure
9896
def test_nocaret(self):
9997
exc = SyntaxError("error", ("x.py", 23, None, "bad syntax"))
10098
err = traceback.format_exception_only(SyntaxError, exc)
@@ -748,8 +746,6 @@ def outer_raise():
748746
self.assertIn('inner_raise() # Marker', blocks[2])
749747
self.check_zero_div(blocks[2])
750748

751-
# TODO: RUSTPYTHON
752-
@unittest.expectedFailure
753749
def test_syntax_error_offset_at_eol(self):
754750
# See #10186.
755751
def e():
@@ -808,8 +804,6 @@ def __str__(self):
808804
exp = f'<unknown>.{X.__qualname__}: I am X\n'
809805
self.assertEqual(exp, err)
810806

811-
# TODO: RUSTPYTHON
812-
@unittest.expectedFailure
813807
def test_syntax_error_various_offsets(self):
814808
for offset in range(-5, 10):
815809
for add in [0, 2]:

‎vm/src/exceptions.rs‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,6 +1602,44 @@ pub(super) mod types {
16021602

16031603
#[pyexception]
16041604
impl PySyntaxError {
1605+
#[pyslot]
1606+
#[pymethod(name = "__init__")]
1607+
fn slot_init(zelf: PyObjectRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult<()> {
1608+
let len = args.args.len();
1609+
let new_args = args;
1610+
1611+
zelf.set_attr("print_file_and_line", vm.ctx.none(), vm)?;
1612+
1613+
if len == 2 {
1614+
if let Ok(location_tuple) = new_args.args[1]
1615+
.clone()
1616+
.downcast::<crate::builtins::PyTuple>()
1617+
{
1618+
#[allow(clippy::len_zero)]
1619+
if location_tuple.len() >= 1 {
1620+
zelf.set_attr("filename", location_tuple.fast_getitem(0).clone(), vm)?;
1621+
}
1622+
if location_tuple.len() >= 2 {
1623+
zelf.set_attr("lineno", location_tuple.fast_getitem(1).clone(), vm)?;
1624+
}
1625+
if location_tuple.len() >= 3 {
1626+
zelf.set_attr("offset", location_tuple.fast_getitem(2).clone(), vm)?;
1627+
}
1628+
if location_tuple.len() >= 4 {
1629+
zelf.set_attr("text", location_tuple.fast_getitem(3).clone(), vm)?;
1630+
}
1631+
if location_tuple.len() >= 5 {
1632+
zelf.set_attr("end_lineno", location_tuple.fast_getitem(4).clone(), vm)?;
1633+
}
1634+
if location_tuple.len() >= 6 {
1635+
zelf.set_attr("end_offset", location_tuple.fast_getitem(5).clone(), vm)?;
1636+
}
1637+
}
1638+
}
1639+
1640+
PyBaseException::slot_init(zelf, new_args, vm)
1641+
}
1642+
16051643
#[pymethod(magic)]
16061644
fn str(exc: PyBaseExceptionRef, vm: &VirtualMachine) -> PyStrRef {
16071645
fn basename(filename: &str) -> &str {

0 commit comments

Comments
 (0)