Skip to content

Commit e6bcd64

Browse files
authored
Validate SyntaxError details tuple shape (#7533)
1 parent 2ebd702 commit e6bcd64

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Lib/test/test_exceptions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2519,7 +2519,6 @@ def test_attributes_old_constructor(self):
25192519
self.assertEqual(error, the_exception.text)
25202520
self.assertEqual("bad bad", the_exception.msg)
25212521

2522-
@unittest.expectedFailure # TODO: RUSTPYTHON
25232522
def test_incorrect_constructor(self):
25242523
args = ("bad.py", 1, 2)
25252524
self.assertRaises(TypeError, SyntaxError, "bad bad", args)

crates/vm/src/exceptions.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,6 +2397,22 @@ pub(super) mod types {
23972397
.downcast::<crate::builtins::PyTuple>()
23982398
{
23992399
let location_tup_len = location_tuple.len();
2400+
2401+
match location_tup_len {
2402+
4 | 6 => {}
2403+
5 => {
2404+
return Err(vm.new_type_error(
2405+
"end_offset must be provided when end_lineno is provided".to_owned(),
2406+
));
2407+
}
2408+
_ => {
2409+
return Err(vm.new_type_error(format!(
2410+
"function takes exactly 4 or 6 arguments ({} given)",
2411+
location_tup_len
2412+
)));
2413+
}
2414+
}
2415+
24002416
for (i, &attr) in [
24012417
"filename",
24022418
"lineno",

0 commit comments

Comments
 (0)