From e6bcd640669391b3d8eaa04bcdfa20e2ea1e31da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Huy=20V=C5=A9=20=28Josh=29?= Date: Sun, 29 Mar 2026 20:37:08 +0700 Subject: [PATCH] Validate SyntaxError details tuple shape (#7533) --- Lib/test/test_exceptions.py | 1 - crates/vm/src/exceptions.rs | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index e7b0e8850..10010ffa9 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -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) diff --git a/crates/vm/src/exceptions.rs b/crates/vm/src/exceptions.rs index f32005bd3..1f82c3cd7 100644 --- a/crates/vm/src/exceptions.rs +++ b/crates/vm/src/exceptions.rs @@ -2397,6 +2397,22 @@ pub(super) mod types { .downcast::() { 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",