From 16a457f5afdd51380bc7987687e1b0afc2e8cbc9 Mon Sep 17 00:00:00 2001 From: ShaharNaveh <50263213+ShaharNaveh@users.noreply.github.com> Date: Tue, 16 Jun 2026 18:56:11 +0300 Subject: [PATCH 1/6] clippy `bool_to_int_with_if` --- Cargo.toml | 1 + crates/codegen/src/compile.rs | 6 +++--- crates/host_env/src/ctypes.rs | 8 ++------ crates/vm/src/builtins/range.rs | 7 +------ crates/vm/src/stdlib/_ctypes/base.rs | 6 +----- 5 files changed, 8 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 81bbdebeb39..e81908b8d7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -382,6 +382,7 @@ use_self = "warn" useless_let_if_seq = "warn" # pedantic lints to enforce gradually +bool_to_int_with_if = "warn" checked_conversions = "warn" cloned_instead_of_copied = "warn" collapsible_else_if = "warn" diff --git a/crates/codegen/src/compile.rs b/crates/codegen/src/compile.rs index c3b86ce46bc..9fde1fc0841 100644 --- a/crates/codegen/src/compile.rs +++ b/crates/codegen/src/compile.rs @@ -4411,10 +4411,10 @@ impl Compiler { .chain(parameters.kwonlyargs.iter().map(|x| &x.parameter)) .chain(parameters.kwarg.as_deref()); - let num_annotations: u32 = + let num_annotations = u32::try_from(parameters_iter.filter(|p| p.annotation.is_some()).count()) .expect("too many annotations") - + if returns.is_some() { 1 } else { 0 }; + + u32::from(returns.is_some()); // Compile annotations inside the annotation scope let parameters_iter = parameters @@ -6925,7 +6925,7 @@ impl Compiler { let has_default = num_cases > 1 && is_trailing_wildcard_default(&cases.last().unwrap().pattern); - let case_count = num_cases - if has_default { 1 } else { 0 }; + let case_count = num_cases - usize::from(has_default); for (i, m) in cases.iter().enumerate().take(case_count) { // Only copy the subject if not on the last case if i != case_count - 1 { diff --git a/crates/host_env/src/ctypes.rs b/crates/host_env/src/ctypes.rs index ae64b06cfe0..9bfd41c2818 100644 --- a/crates/host_env/src/ctypes.rs +++ b/crates/host_env/src/ctypes.rs @@ -1096,7 +1096,7 @@ pub fn simple_storage_value_to_bytes_endian( result } "?" => match value { - SimpleStorageValue::Bool(value) => vec![if value { 1 } else { 0 }], + SimpleStorageValue::Bool(value) => vec![u8::from(value)], _ => vec![0], }, "v" => match value { @@ -1435,11 +1435,7 @@ pub fn ffi_value_from_type_code(type_code: &str, buffer: &[u8]) -> FfiValue { .map_or(0.0, f64::from_ne_bytes), ), "z" | "Z" | "P" | "O" => FfiValue::Pointer(read_pointer_from_buffer(buffer)), - "?" => FfiValue::U8(if buffer.first().is_some_and(|&b| b != 0) { - 1 - } else { - 0 - }), + "?" => FfiValue::U8(u8::from(buffer.first().is_some_and(|&b| b != 0))), "u" => FfiValue::U32(buffer.first_chunk().copied().map_or(0, u32::from_ne_bytes)), _ => FfiValue::Pointer(0), } diff --git a/crates/vm/src/builtins/range.rs b/crates/vm/src/builtins/range.rs index ef141cdd69d..415d34fdb05 100644 --- a/crates/vm/src/builtins/range.rs +++ b/crates/vm/src/builtins/range.rs @@ -406,12 +406,7 @@ impl Py { #[pymethod] fn count(&self, item: PyObjectRef, vm: &VirtualMachine) -> PyResult { if let Ok(int) = item.clone().downcast::() { - let count = if self.index_of(int.as_bigint()).is_some() { - 1 - } else { - 0 - }; - Ok(count) + Ok(usize::from(self.index_of(int.as_bigint()).is_some())) } else { // Dealing with classes who might compare equal with ints in their // __eq__, slow search. diff --git a/crates/vm/src/stdlib/_ctypes/base.rs b/crates/vm/src/stdlib/_ctypes/base.rs index a339e362786..62856c4cef8 100644 --- a/crates/vm/src/stdlib/_ctypes/base.rs +++ b/crates/vm/src/stdlib/_ctypes/base.rs @@ -1111,11 +1111,7 @@ impl PyCData { fn _b_needsfree_(&self) -> i32 { // Borrowed (from_address) or has base object → 0 (don't free) // Owned and no base → 1 (need to free) - if self.is_borrowed() || self.base.read().is_some() { - 0 - } else { - 1 - } + i32::from(!(self.is_borrowed() || self.base.read().is_some())) } // CDataType_methods - shared across all ctypes types From aaeed680584e4ef82a5de8c75dd0a4dbdba77d9d Mon Sep 17 00:00:00 2001 From: ShaharNaveh <50263213+ShaharNaveh@users.noreply.github.com> Date: Tue, 16 Jun 2026 19:00:38 +0300 Subject: [PATCH 2/6] doc_link_with_quotes --- Cargo.toml | 1 + crates/vm/src/warn.rs | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e81908b8d7e..16c26df1b30 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -387,6 +387,7 @@ checked_conversions = "warn" cloned_instead_of_copied = "warn" collapsible_else_if = "warn" comparison_chain = "warn" +doc_link_with_quotes = "warn" duration_suboptimal_units = "warn" explicit_deref_methods = "warn" explicit_into_iter_loop = "warn" diff --git a/crates/vm/src/warn.rs b/crates/vm/src/warn.rs index 081a9621ba1..6500e8de0f6 100644 --- a/crates/vm/src/warn.rs +++ b/crates/vm/src/warn.rs @@ -138,7 +138,7 @@ fn get_warnings_attr( module.get_attr(attr_name, vm).ok() } -/// Get the warnings filters list from sys.modules['warnings'].filters, +/// Get the warnings filters list from `sys.modules['warnings'].filters`, /// falling back to vm.state.warnings.filters. fn get_warnings_filters(vm: &VirtualMachine) -> PyListRef { if let Some(filters_obj) = get_warnings_attr(vm, identifier!(&vm.ctx, filters), false) @@ -149,7 +149,7 @@ fn get_warnings_filters(vm: &VirtualMachine) -> PyListRef { vm.state.warnings.filters.clone() } -/// Get the default action from sys.modules['warnings']._defaultaction, +/// Get the default action from `sys.modules['warnings']._defaultaction`, /// falling back to vm.state.warnings.default_action. fn get_default_action(vm: &VirtualMachine) -> PyResult { if let Some(action) = get_warnings_attr(vm, identifier!(&vm.ctx, defaultaction), false) { @@ -164,7 +164,7 @@ fn get_default_action(vm: &VirtualMachine) -> PyResult { Ok(vm.state.warnings.default_action.clone().into()) } -/// Get the once registry from sys.modules['warnings']._onceregistry, +/// Get the once registry from `sys.modules['warnings']._onceregistry`, /// falling back to vm.state.warnings.once_registry. fn get_once_registry(vm: &VirtualMachine) -> PyResult { if let Some(registry) = get_warnings_attr(vm, identifier!(&vm.ctx, onceregistry), false) { From 026786b949bb830f44844a3f70dc4ca846046eb6 Mon Sep 17 00:00:00 2001 From: ShaharNaveh <50263213+ShaharNaveh@users.noreply.github.com> Date: Tue, 16 Jun 2026 19:10:33 +0300 Subject: [PATCH 3/6] ip_constant --- Cargo.toml | 1 + crates/stdlib/src/ssl.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 16c26df1b30..4cb5118fa08 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -399,6 +399,7 @@ from_iter_instead_of_collect = "warn" inconsistent_struct_constructor = "warn" index_refutable_slice = "warn" inefficient_to_string = "warn" +ip_constant = "warn" iter_filter_is_ok = "warn" iter_filter_is_some = "warn" manual_is_variant_and = "warn" diff --git a/crates/stdlib/src/ssl.rs b/crates/stdlib/src/ssl.rs index d4a01c9b131..35cb1794045 100644 --- a/crates/stdlib/src/ssl.rs +++ b/crates/stdlib/src/ssl.rs @@ -3496,7 +3496,7 @@ mod _ssl { // When server_hostname=None, use an IP address to suppress SNI // no hostname = no SNI extension ServerName::IpAddress( - core::net::IpAddr::V4(core::net::Ipv4Addr::new(127, 0, 0, 1)).into(), + core::net::IpAddr::V4(core::net::Ipv4Addr::LOCALHOST).into(), ) }; From 27e4a76c24440d480c2f997d626f5bf46943bdbf Mon Sep 17 00:00:00 2001 From: ShaharNaveh <50263213+ShaharNaveh@users.noreply.github.com> Date: Tue, 16 Jun 2026 19:47:51 +0300 Subject: [PATCH 4/6] single_char_pattern --- Cargo.toml | 1 + crates/vm/src/stdlib/_ast.rs | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4cb5118fa08..0ee0516dab9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -413,6 +413,7 @@ option_as_ref_cloned = "warn" ptr_offset_by_literal = "warn" redundant_else = "warn" return_self_not_must_use = "warn" +single_char_pattern = "warn" uninlined_format_args = "warn" unnecessary_wraps = "warn" unnested_or_patterns = "warn" diff --git a/crates/vm/src/stdlib/_ast.rs b/crates/vm/src/stdlib/_ast.rs index 57da9b3c3a8..38e0d546f44 100644 --- a/crates/vm/src/stdlib/_ast.rs +++ b/crates/vm/src/stdlib/_ast.rs @@ -512,14 +512,17 @@ pub(crate) fn parse_func_type( fn type_ignores_from_source(vm: &VirtualMachine, source: &str) -> Vec { let mut ignores = Vec::new(); for (idx, line) in source.lines().enumerate() { - let Some(pos) = line.find("#") else { + let Some(pos) = line.find('#') else { continue; }; + let comment = &line[pos + 1..]; let comment = comment.trim_start(); + let Some(rest) = comment.strip_prefix("type: ignore") else { continue; }; + let tag = rest.trim_start(); let tag = if tag.is_empty() { "" } else { tag }; let node = NodeAst From 5a7225193c028c501d6a74f3daa4f17acf91b536 Mon Sep 17 00:00:00 2001 From: ShaharNaveh <50263213+ShaharNaveh@users.noreply.github.com> Date: Tue, 16 Jun 2026 19:29:43 +0300 Subject: [PATCH 5/6] more rules --- Cargo.toml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 0ee0516dab9..80a0e86e6d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -402,6 +402,8 @@ inefficient_to_string = "warn" ip_constant = "warn" iter_filter_is_ok = "warn" iter_filter_is_some = "warn" +large_futures = "warn" +manual_instant_elapsed = "warn" manual_is_variant_and = "warn" map_unwrap_or = "warn" match_bool = "warn" @@ -409,11 +411,17 @@ must_use_candidate = "warn" mut_mut = "warn" needless_bitwise_bool = "warn" needless_for_each = "warn" +non_std_lazy_statics = "warn" option_as_ref_cloned = "warn" ptr_offset_by_literal = "warn" +range_minus_one = "warn" +range_plus_one = "warn" redundant_else = "warn" return_self_not_must_use = "warn" single_char_pattern = "warn" +unchecked_time_subtraction = "warn" uninlined_format_args = "warn" +unnecessary_box_returns = "warn" +unnecessary_join = "warn" unnecessary_wraps = "warn" unnested_or_patterns = "warn" From a51feed765120519c6520e6095a7d8564bcbdfc8 Mon Sep 17 00:00:00 2001 From: ShaharNaveh <50263213+ShaharNaveh@users.noreply.github.com> Date: Tue, 16 Jun 2026 20:28:16 +0300 Subject: [PATCH 6/6] windows --- crates/host_env/src/overlapped.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/host_env/src/overlapped.rs b/crates/host_env/src/overlapped.rs index d84897d620d..be5e75f585f 100644 --- a/crates/host_env/src/overlapped.rs +++ b/crates/host_env/src/overlapped.rs @@ -892,7 +892,7 @@ unsafe extern "system" fn post_to_queue_callback( unsafe { let _ = windows_sys::Win32::System::IO::PostQueuedCompletionStatus( data.completion_port, - if timer_or_wait_fired { 1 } else { 0 }, + u32::from(timer_or_wait_fired), 0, data.overlapped, );