From 6d1ea6d996bd7c4256b50eb7e15df7abe0165382 Mon Sep 17 00:00:00 2001 From: Padraic Fanning Date: Thu, 24 Feb 2022 19:57:00 -0500 Subject: [PATCH 1/5] Fix let_underscore_lock Clippy errror --- vm/src/stdlib/io.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/src/stdlib/io.rs b/vm/src/stdlib/io.rs index c312a7459..fb9162eae 100644 --- a/vm/src/stdlib/io.rs +++ b/vm/src/stdlib/io.rs @@ -3277,7 +3277,7 @@ mod _io { #[pymethod] fn close(self, vm: &VirtualMachine) -> PyResult<()> { - let _ = self.try_resizable(vm)?; + drop(self.try_resizable(vm)?); self.closed.store(true); Ok(()) } From 88e0f1399361bd84a760f19d4413962fa6682b8d Mon Sep 17 00:00:00 2001 From: Padraic Fanning Date: Thu, 24 Feb 2022 20:12:10 -0500 Subject: [PATCH 2/5] Fix unnecessary_lazy_evaluations Clippy warning --- derive/src/pyclass.rs | 2 +- stdlib/src/socket.rs | 2 +- vm/src/builtins/slice.rs | 10 ++++------ vm/src/cformat.rs | 2 +- vm/src/stdlib/io.rs | 7 ++----- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/derive/src/pyclass.rs b/derive/src/pyclass.rs index 7a634d5a6..a27150995 100644 --- a/derive/src/pyclass.rs +++ b/derive/src/pyclass.rs @@ -636,7 +636,7 @@ impl GetSetNursery { for ((name, _cfgs), (getter, setter, deleter)) in self.map.iter() { if getter.is_none() { errors.push(syn::Error::new_spanned( - setter.as_ref().or_else(|| deleter.as_ref()).unwrap(), + setter.as_ref().or(deleter.as_ref()).unwrap(), format!("Property '{}' is missing a getter", name), )); }; diff --git a/stdlib/src/socket.rs b/stdlib/src/socket.rs index 9543c02b2..4af5f8b2b 100644 --- a/stdlib/src/socket.rs +++ b/stdlib/src/socket.rs @@ -1114,7 +1114,7 @@ mod _socket { let abstractpath = &path_u8[..abstractaddrlen]; vm.ctx.new_bytes(abstractpath.to_vec()).into() } else { - let len = memchr::memchr(b'\0', path_u8).unwrap_or_else(|| path_u8.len()); + let len = memchr::memchr(b'\0', path_u8).unwrap_or(path_u8.len()); let path = &path_u8[..len]; vm.ctx.new_str(String::from_utf8_lossy(path)).into() } diff --git a/vm/src/builtins/slice.rs b/vm/src/builtins/slice.rs index add827d7d..3d2b6d1e4 100644 --- a/vm/src/builtins/slice.rs +++ b/vm/src/builtins/slice.rs @@ -395,12 +395,10 @@ fn to_isize_index(vm: &VirtualMachine, obj: &PyObject) -> PyResult })?; let value = result.as_bigint(); let is_negative = value.is_negative(); - Ok(Some(value.to_isize().unwrap_or_else(|| { - if is_negative { - isize::MIN - } else { - isize::MAX - } + Ok(Some(value.to_isize().unwrap_or(if is_negative { + isize::MIN + } else { + isize::MAX }))) } diff --git a/vm/src/cformat.rs b/vm/src/cformat.rs index bcf2adb10..7e1267f77 100644 --- a/vm/src/cformat.rs +++ b/vm/src/cformat.rs @@ -140,7 +140,7 @@ impl CFormatSpec { let precision = parse_precision(iter)?; consume_length(iter); let (format_type, format_char) = parse_format_type(iter)?; - let precision = precision.or_else(|| match format_type { + let precision = precision.or(match format_type { CFormatType::Float(_) => Some(CFormatQuantity::Amount(6)), _ => None, }); diff --git a/vm/src/stdlib/io.rs b/vm/src/stdlib/io.rs index fb9162eae..78b8b6595 100644 --- a/vm/src/stdlib/io.rs +++ b/vm/src/stdlib/io.rs @@ -1567,7 +1567,7 @@ mod _io { let mut data = self.reader().lock(vm)?; let raw = data.check_init(vm)?; ensure_unclosed(raw, "read of closed file", vm)?; - let n = size.to_usize().unwrap_or_else(|| data.buffer.len()); + let n = size.to_usize().unwrap_or(data.buffer.len()); if n == 0 { return Ok(Vec::new()); } @@ -3214,10 +3214,7 @@ mod _io { #[pymethod] #[pymethod(name = "read1")] fn read(self, size: OptionalSize, vm: &VirtualMachine) -> PyResult> { - let buf = self - .buffer(vm)? - .read(size.to_usize()) - .unwrap_or_else(Vec::new); + let buf = self.buffer(vm)?.read(size.to_usize()).unwrap_or_default(); Ok(buf) } From 0abcd4c0aa5a298e2210a9373378098371b36a90 Mon Sep 17 00:00:00 2001 From: Padraic Fanning Date: Thu, 24 Feb 2022 20:13:24 -0500 Subject: [PATCH 3/5] Fix unwrap_or_else_default Clippy warning --- derive/src/pymodule.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/derive/src/pymodule.rs b/derive/src/pymodule.rs index 28124aeca..d4546c6f8 100644 --- a/derive/src/pymodule.rs +++ b/derive/src/pymodule.rs @@ -119,7 +119,7 @@ fn new_module_item( }), "pyclass" => Box::new(ClassItem { inner: ContentItemInner { index, attr_name }, - pyattrs: pyattrs.unwrap_or_else(Vec::new), + pyattrs: pyattrs.unwrap_or_default(), }), other => unreachable!("#[pymodule] doesn't accept #[{}]", other), } From 29048b105e5cd86341289de11cb9daa014fe8ac8 Mon Sep 17 00:00:00 2001 From: Padraic Fanning Date: Thu, 24 Feb 2022 20:34:23 -0500 Subject: [PATCH 4/5] Fix needless_late_init Clippy warning --- common/src/cmp.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/common/src/cmp.rs b/common/src/cmp.rs index c148305ca..d182340a9 100644 --- a/common/src/cmp.rs +++ b/common/src/cmp.rs @@ -15,15 +15,11 @@ pub fn timing_safe_cmp(a: &[u8], b: &[u8]) -> bool { * chance to optimize and fold the code in any way that may change * the timing. */ - let length: Volatile; - let mut left: Volatile<*const u8>; - let mut right: Volatile<*const u8>; let mut result: u8 = 0; - /* loop count depends on length of b */ - length = Volatile::new(len_b); - left = Volatile::new(std::ptr::null()); - right = Volatile::new(b); + let length: Volatile = Volatile::new(len_b); + let mut left: Volatile<*const u8> = Volatile::new(std::ptr::null()); + let mut right: Volatile<*const u8> = Volatile::new(b); /* don't use else here to keep the amount of CPU instructions constant, * volatile forces re-evaluation From edbc17fb38e5529cab842d1b70cff5e61f1df291 Mon Sep 17 00:00:00 2001 From: Padraic Fanning Date: Thu, 24 Feb 2022 21:19:36 -0500 Subject: [PATCH 5/5] Skip flaky test --- Lib/test/test_threading.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index 4080b0a74..2bbad2dcc 100644 --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -1061,6 +1061,7 @@ class ThreadingExceptionTests(BaseTestCase): lock = threading.Lock() self.assertRaises(RuntimeError, lock.release) + @unittest.skip("TODO: RUSTPYTHON, flaky test") def test_recursion_limit(self): # Issue 9670 # test that excessive recursion within a non-main thread causes