From 76236682564d53da2853e45daf9da205628b657f Mon Sep 17 00:00:00 2001 From: Ankit Goel Date: Mon, 23 Sep 2024 21:20:17 +0100 Subject: [PATCH] Raise TypeError if BaseException receives Keyword arguments --- Lib/test/test_exceptions.py | 2 -- vm/src/exceptions.rs | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 000ef02d9..47e789496 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -668,8 +668,6 @@ class ExceptionTests(unittest.TestCase): e.__suppress_context__ = False self.assertFalse(e.__suppress_context__) - # TODO: RUSTPYTHON - @unittest.expectedFailure def testKeywordArgs(self): # test that builtin exception don't take keyword args, # but user-defined subclasses can if they want diff --git a/vm/src/exceptions.rs b/vm/src/exceptions.rs index 66ceeca67..0b61c9017 100644 --- a/vm/src/exceptions.rs +++ b/vm/src/exceptions.rs @@ -649,6 +649,9 @@ impl Constructor for PyBaseException { type Args = FuncArgs; fn py_new(cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult { + if cls.is(PyBaseException::class(&vm.ctx)) && !args.kwargs.is_empty() { + return Err(vm.new_type_error("BaseException() takes no keyword arguments".to_owned())); + } PyBaseException::new(args.args, vm) .into_ref_with_type(vm, cls) .map(Into::into)