mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 03:04:38 +08:00
Fix ImportError
This commit is contained in:
1 parent
d78ed67c26
commit
e4c8f2bb43
2 files changed
+15
-15
No files matched your search
Vendored
-4
@@ -2349,8 +2349,6 @@ class AttributeErrorTests(unittest.TestCase):
|
||||
|
||||
|
||||
class ImportErrorTests(unittest.TestCase):
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_attributes(self):
|
||||
# Setting 'name' and 'path' should not be a problem.
|
||||
exc = ImportError('test')
|
||||
@@ -2385,8 +2383,6 @@ class ImportErrorTests(unittest.TestCase):
|
||||
with self.assertRaisesRegex(TypeError, msg):
|
||||
ImportError('test', invalid='keyword', another=True)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_reset_attributes(self):
|
||||
exc = ImportError('test', name='name', path='path')
|
||||
self.assertEqual(exc.args, ('test',))
|
||||
|
||||
+15
-11
@@ -1308,17 +1308,21 @@ pub(super) mod types {
|
||||
args: ::rustpython_vm::function::FuncArgs,
|
||||
vm: &::rustpython_vm::VirtualMachine,
|
||||
) -> ::rustpython_vm::PyResult<()> {
|
||||
zelf.set_attr(
|
||||
"name",
|
||||
vm.unwrap_or_none(args.kwargs.get("name").cloned()),
|
||||
vm,
|
||||
)?;
|
||||
zelf.set_attr(
|
||||
"path",
|
||||
vm.unwrap_or_none(args.kwargs.get("path").cloned()),
|
||||
vm,
|
||||
)?;
|
||||
Ok(())
|
||||
let mut kwargs = args.kwargs.clone();
|
||||
let name = kwargs.swap_remove("name");
|
||||
let path = kwargs.swap_remove("path");
|
||||
|
||||
// Check for any remaining invalid keyword arguments
|
||||
if let Some(invalid_key) = kwargs.keys().next() {
|
||||
return Err(vm.new_type_error(format!(
|
||||
"'{}' is an invalid keyword argument for ImportError",
|
||||
invalid_key
|
||||
)));
|
||||
}
|
||||
|
||||
zelf.set_attr("name", vm.unwrap_or_none(name), vm)?;
|
||||
zelf.set_attr("path", vm.unwrap_or_none(path), vm)?;
|
||||
PyBaseException::slot_init(zelf, args, vm)
|
||||
}
|
||||
#[pymethod(magic)]
|
||||
fn reduce(exc: PyBaseExceptionRef, vm: &VirtualMachine) -> PyTupleRef {
|
||||
|
||||
Reference in new issue
Block a user