From a4d92cbac05f5dcef182567c0667d851336f9b84 Mon Sep 17 00:00:00 2001 From: coolreader18 <33094578+coolreader18@users.noreply.github.com> Date: Mon, 19 Aug 2019 14:30:10 -0500 Subject: [PATCH 1/4] Fix os.chmod not defined on windows --- vm/src/stdlib/os.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/vm/src/stdlib/os.rs b/vm/src/stdlib/os.rs index 19eabb598..d61670be4 100644 --- a/vm/src/stdlib/os.rs +++ b/vm/src/stdlib/os.rs @@ -1096,12 +1096,11 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef { } } } - let support_funcs = vec![ + let mut support_funcs = vec![ SupportFunc::new(vm, "open", os_open, None, Some(false), None), // access Some Some None SupportFunc::new(vm, "chdir", os_chdir, Some(false), None, None), // chflags Some, None Some - SupportFunc::new(vm, "chmod", os_chmod, Some(false), Some(false), Some(false)), // chown Some Some Some // chroot Some None None SupportFunc::new(vm, "listdir", os_listdir, Some(false), None, None), @@ -1121,6 +1120,15 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef { SupportFunc::new(vm, "unlink", os_remove, Some(false), Some(false), None), // utime Some Some Some ]; + #[cfg(unix)] + support_funcs.extend(vec![SupportFunc::new( + vm, + "chmod", + os_chmod, + Some(false), + Some(false), + Some(false), + )]); let supports_fd = PySet::default().into_ref(vm); let supports_dir_fd = PySet::default().into_ref(vm); let supports_follow_symlinks = PySet::default().into_ref(vm); From da92c4acd5690680ae0c0a8339f471f5349d513f Mon Sep 17 00:00:00 2001 From: Marcin Pajkowski Date: Tue, 20 Aug 2019 00:51:06 +0200 Subject: [PATCH 2/4] Fix failing os.chmod tests --- tests/snippets/stdlib_os.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/snippets/stdlib_os.py b/tests/snippets/stdlib_os.py index 647fee09d..c3a1beec4 100644 --- a/tests/snippets/stdlib_os.py +++ b/tests/snippets/stdlib_os.py @@ -233,8 +233,9 @@ with TestWithTempDir() as tmpdir: os.stat(fname, follow_symlinks=False).st_mode == os.stat(symlink_file, follow_symlinks=False).st_mode # os.chmod - os.chmod(fname, 0o666) - assert oct(os.stat(fname).st_mode) == '0o100666' + if os.name != "nt": + os.chmod(fname, 0o666) + assert oct(os.stat(fname).st_mode) == '0o100666' # os.path assert os.path.exists(fname) == True From d7187d426cff3fd0468eed1cbdd1c1639c292917 Mon Sep 17 00:00:00 2001 From: Tommaso Thea Cioni Date: Thu, 22 Aug 2019 03:11:51 +0200 Subject: [PATCH 3/4] Cleaned up two tests. --- tests/benchmarks/perf_add.py | 3 --- tests/benchmarks/perf_fib.py | 8 +++----- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/tests/benchmarks/perf_add.py b/tests/benchmarks/perf_add.py index 724c2fb26..e2846ed4e 100644 --- a/tests/benchmarks/perf_add.py +++ b/tests/benchmarks/perf_add.py @@ -1,11 +1,8 @@ j = 0 while j < 1000: - total = 0 i = 0 while i < 100: total += i i += 1 - # print(total) - j += 1 diff --git a/tests/benchmarks/perf_fib.py b/tests/benchmarks/perf_fib.py index 8c508fd06..89ede8517 100644 --- a/tests/benchmarks/perf_fib.py +++ b/tests/benchmarks/perf_fib.py @@ -1,17 +1,15 @@ def fib(n): - # a, b = 1, 1 a = 1 b = 1 - for _ in range(n-1): + for _ in range(n - 1): temp = b - b = a+b + b = a + b a = temp - #a, b = b, a+b return b print(fib(1)) print(fib(2)) print(fib(3)) print(fib(4)) -print(fib(5)) +print(fib(5)) \ No newline at end of file From 0327428aa5e7fa259dc2a30e2c4eda51fe83a16e Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Wed, 21 Aug 2019 01:24:38 +0900 Subject: [PATCH 4/4] bool.real --- tests/snippets/bools.py | 5 +++++ vm/src/obj/objbool.rs | 2 +- vm/src/obj/objint.rs | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/snippets/bools.py b/tests/snippets/bools.py index c33fcff0f..e9d41c5d5 100644 --- a/tests/snippets/bools.py +++ b/tests/snippets/bools.py @@ -80,6 +80,11 @@ assert False.__xor__(False) is False assert False.__rxor__(0) is not False assert False.__rxor__(False) is False +assert True.real == 1 +assert True.imag == 0 +assert type(True.real) is int +assert type(True.imag) is int + # Check work for sequence and map assert bool({}) is False assert bool([]) is False diff --git a/vm/src/obj/objbool.rs b/vm/src/obj/objbool.rs index 19d95889f..91d47c626 100644 --- a/vm/src/obj/objbool.rs +++ b/vm/src/obj/objbool.rs @@ -77,7 +77,7 @@ The class bool is a subclass of the class int, and cannot be subclassed."; "__rand__" => context.new_rustfunc(bool_rand), "__xor__" => context.new_rustfunc(bool_xor), "__rxor__" => context.new_rustfunc(bool_rxor), - "__doc__" => context.new_str(bool_doc.to_string()) + "__doc__" => context.new_str(bool_doc.to_string()), }); } diff --git a/vm/src/obj/objint.rs b/vm/src/obj/objint.rs index 478671257..296f45866 100644 --- a/vm/src/obj/objint.rs +++ b/vm/src/obj/objint.rs @@ -681,8 +681,8 @@ impl PyInt { Ok(PyBytes::new(bytes)) } #[pyproperty] - fn real(zelf: PyRef, _vm: &VirtualMachine) -> PyIntRef { - zelf + fn real(&self, vm: &VirtualMachine) -> PyObjectRef { + vm.ctx.new_int(self.value.clone()) } #[pyproperty]