Skip to content

Commit 7623668

Browse files
crazymerlynyouknowone
authored andcommitted
Raise TypeError if BaseException receives Keyword arguments
1 parent bbf7aac commit 7623668

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

Lib/test/test_exceptions.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,8 +668,6 @@ def testChainingDescriptors(self):
668668
e.__suppress_context__ = False
669669
self.assertFalse(e.__suppress_context__)
670670

671-
# TODO: RUSTPYTHON
672-
@unittest.expectedFailure
673671
def testKeywordArgs(self):
674672
# test that builtin exception don't take keyword args,
675673
# but user-defined subclasses can if they want

vm/src/exceptions.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,9 @@ impl Constructor for PyBaseException {
649649
type Args = FuncArgs;
650650

651651
fn py_new(cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
652+
if cls.is(PyBaseException::class(&vm.ctx)) && !args.kwargs.is_empty() {
653+
return Err(vm.new_type_error("BaseException() takes no keyword arguments".to_owned()));
654+
}
652655
PyBaseException::new(args.args, vm)
653656
.into_ref_with_type(vm, cls)
654657
.map(Into::into)

0 commit comments

Comments
 (0)