Raise TypeError if BaseException receives Keyword arguments

This commit is contained in:
Ankit Goel authored and Jeong, YunWon committed 2024-09-24 11:57:37 +09:00
1 parent bbf7aacd4d
commit 7623668256
2 files changed
+3 -2

No files matched your search

-2
View File
@@ -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
+3
View File
@@ -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)