Validate SyntaxError details tuple shape (#7533)

This commit is contained in:
Huy Vũ (Josh)
2026-03-29 20:37:08 +07:00
committed by GitHub
parent 2ebd7026e4
commit e6bcd64066
2 changed files with 16 additions and 1 deletions

View File

@@ -2519,7 +2519,6 @@ class SyntaxErrorTests(unittest.TestCase):
self.assertEqual(error, the_exception.text)
self.assertEqual("bad bad", the_exception.msg)
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_incorrect_constructor(self):
args = ("bad.py", 1, 2)
self.assertRaises(TypeError, SyntaxError, "bad bad", args)

View File

@@ -2397,6 +2397,22 @@ pub(super) mod types {
.downcast::<crate::builtins::PyTuple>()
{
let location_tup_len = location_tuple.len();
match location_tup_len {
4 | 6 => {}
5 => {
return Err(vm.new_type_error(
"end_offset must be provided when end_lineno is provided".to_owned(),
));
}
_ => {
return Err(vm.new_type_error(format!(
"function takes exactly 4 or 6 arguments ({} given)",
location_tup_len
)));
}
}
for (i, &attr) in [
"filename",
"lineno",