diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py index 63a7b45d06..da4329048e 100644 --- a/Lib/test/test_cmd_line.py +++ b/Lib/test/test_cmd_line.py @@ -75,8 +75,6 @@ def test_verbose(self): rc, out, err = assert_python_ok('-vv') self.assertNotIn(b'stack overflow', err) - # TODO: RUSTPYTHON - @unittest.expectedFailure @unittest.skipIf(interpreter_requires_environment(), 'Cannot run -E tests when PYTHON env vars are required.') def test_xoptions(self): diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 55f4f04dac..5ade946b57 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -761,8 +761,6 @@ def test_env(self): stdout, stderr = p.communicate() self.assertEqual(stdout, b"orange") - # TODO: RUSTPYTHON - @unittest.expectedFailure # Windows requires at least the SYSTEMROOT environment variable to start # Python @unittest.skipIf(sys.platform == 'win32', diff --git a/extra_tests/snippets/syntax_non_utf8.py b/extra_tests/snippets/syntax_non_utf8.py index 731b36889c..247454eeec 100644 --- a/extra_tests/snippets/syntax_non_utf8.py +++ b/extra_tests/snippets/syntax_non_utf8.py @@ -5,8 +5,6 @@ dir_path = os.path.dirname(os.path.realpath(__file__)) -# TODO: RUSTPYTHON, RustPython raises a SyntaxError here, but cpython raise a ValueError -error = SyntaxError if platform.python_implementation() == 'RustPython' else ValueError -with assert_raises(error): +with assert_raises(ValueError): with open(os.path.join(dir_path , "non_utf8.txt")) as f: eval(f.read()) diff --git a/vm/src/stdlib/builtins.rs b/vm/src/stdlib/builtins.rs index 8f3d99e473..2679a9ab39 100644 --- a/vm/src/stdlib/builtins.rs +++ b/vm/src/stdlib/builtins.rs @@ -24,8 +24,8 @@ mod builtins { format::call_object_format, function::Either, function::{ - ArgBytesLike, ArgCallable, ArgIntoBool, ArgIterable, ArgMapping, FuncArgs, KwArgs, - OptionalArg, OptionalOption, PosArgs, PyArithmeticValue, + ArgBytesLike, ArgCallable, ArgIntoBool, ArgIterable, ArgMapping, ArgStrOrBytesLike, + FuncArgs, KwArgs, OptionalArg, OptionalOption, PosArgs, PyArithmeticValue, }, protocol::{PyIter, PyIterReturn}, py_io, @@ -248,11 +248,34 @@ mod builtins { #[cfg(feature = "rustpython-compiler")] #[pyfunction] fn eval( - source: Either>, + source: Either>, scope: ScopeArgs, vm: &VirtualMachine, ) -> PyResult { - run_code(vm, source, scope, compile::Mode::Eval, "eval") + // source as string + let code = match source { + Either::A(either) => { + let source: &[u8] = &either.borrow_bytes(); + if source.contains(&0) { + return Err(vm.new_value_error( + "source code string cannot contain null bytes".to_owned(), + )); + } + + let source = std::str::from_utf8(source).map_err(|err| { + let msg = format!( + "(unicode error) 'utf-8' codec can't decode byte 0x{:x?} in position {}: invalid start byte", + source[err.valid_up_to()], + err.valid_up_to() + ); + + vm.new_exception_msg(vm.ctx.exceptions.syntax_error.to_owned(), msg) + })?; + Ok(Either::A(vm.ctx.new_str(source))) + } + Either::B(code) => Ok(Either::B(code)), + }?; + run_code(vm, code, scope, compile::Mode::Eval, "eval") } /// Implements `exec`