mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Fix SyntaxError
This commit is contained in:
committed by
Jeong, YunWon
parent
a186a5a9f5
commit
44d66dcdac
6
Lib/test/test_exceptions.py
vendored
6
Lib/test/test_exceptions.py
vendored
@@ -425,8 +425,6 @@ class ExceptionTests(unittest.TestCase):
|
||||
with self.assertRaisesRegex(OSError, 'Windows Error 0x%x' % code):
|
||||
ctypes.pythonapi.PyErr_SetFromWindowsErr(code)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def testAttributes(self):
|
||||
# test that exception attributes are happy
|
||||
|
||||
@@ -2567,8 +2565,6 @@ class SyntaxErrorTests(unittest.TestCase):
|
||||
finally:
|
||||
unlink(TESTFN)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_attributes_new_constructor(self):
|
||||
args = ("bad.py", 1, 2, "abcdefg", 1, 100)
|
||||
the_exception = SyntaxError("bad bad", args)
|
||||
@@ -2581,8 +2577,6 @@ class SyntaxErrorTests(unittest.TestCase):
|
||||
self.assertEqual(error, the_exception.text)
|
||||
self.assertEqual("bad bad", the_exception.msg)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_attributes_old_constructor(self):
|
||||
args = ("bad.py", 1, 2, "abcdefg")
|
||||
the_exception = SyntaxError("bad bad", args)
|
||||
|
||||
6
Lib/test/test_traceback.py
vendored
6
Lib/test/test_traceback.py
vendored
@@ -93,8 +93,6 @@ class TracebackCases(unittest.TestCase):
|
||||
self.assertEqual(err[1].find("("), err[2].find("^")) # in the right place
|
||||
self.assertEqual(err[2].count("^"), 1)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_nocaret(self):
|
||||
exc = SyntaxError("error", ("x.py", 23, None, "bad syntax"))
|
||||
err = traceback.format_exception_only(SyntaxError, exc)
|
||||
@@ -748,8 +746,6 @@ class BaseExceptionReportingTests:
|
||||
self.assertIn('inner_raise() # Marker', blocks[2])
|
||||
self.check_zero_div(blocks[2])
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_syntax_error_offset_at_eol(self):
|
||||
# See #10186.
|
||||
def e():
|
||||
@@ -808,8 +804,6 @@ class BaseExceptionReportingTests:
|
||||
exp = f'<unknown>.{X.__qualname__}: I am X\n'
|
||||
self.assertEqual(exp, err)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_syntax_error_various_offsets(self):
|
||||
for offset in range(-5, 10):
|
||||
for add in [0, 2]:
|
||||
|
||||
@@ -1602,6 +1602,44 @@ pub(super) mod types {
|
||||
|
||||
#[pyexception]
|
||||
impl PySyntaxError {
|
||||
#[pyslot]
|
||||
#[pymethod(name = "__init__")]
|
||||
fn slot_init(zelf: PyObjectRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult<()> {
|
||||
let len = args.args.len();
|
||||
let new_args = args;
|
||||
|
||||
zelf.set_attr("print_file_and_line", vm.ctx.none(), vm)?;
|
||||
|
||||
if len == 2 {
|
||||
if let Ok(location_tuple) = new_args.args[1]
|
||||
.clone()
|
||||
.downcast::<crate::builtins::PyTuple>()
|
||||
{
|
||||
#[allow(clippy::len_zero)]
|
||||
if location_tuple.len() >= 1 {
|
||||
zelf.set_attr("filename", location_tuple.fast_getitem(0).clone(), vm)?;
|
||||
}
|
||||
if location_tuple.len() >= 2 {
|
||||
zelf.set_attr("lineno", location_tuple.fast_getitem(1).clone(), vm)?;
|
||||
}
|
||||
if location_tuple.len() >= 3 {
|
||||
zelf.set_attr("offset", location_tuple.fast_getitem(2).clone(), vm)?;
|
||||
}
|
||||
if location_tuple.len() >= 4 {
|
||||
zelf.set_attr("text", location_tuple.fast_getitem(3).clone(), vm)?;
|
||||
}
|
||||
if location_tuple.len() >= 5 {
|
||||
zelf.set_attr("end_lineno", location_tuple.fast_getitem(4).clone(), vm)?;
|
||||
}
|
||||
if location_tuple.len() >= 6 {
|
||||
zelf.set_attr("end_offset", location_tuple.fast_getitem(5).clone(), vm)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PyBaseException::slot_init(zelf, new_args, vm)
|
||||
}
|
||||
|
||||
#[pymethod(magic)]
|
||||
fn str(exc: PyBaseExceptionRef, vm: &VirtualMachine) -> PyStrRef {
|
||||
fn basename(filename: &str) -> &str {
|
||||
|
||||
Reference in New Issue
Block a user