Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
flamescope = { version = "0.1.2", optional = true }

rustls = { workspace = true, optional = true }
rustls-graviola = { workspace = true, optional = true }

Check warning on line 52 in Cargo.toml

View workflow job for this annotation

GitHub Actions / cargo shear

shear/misplaced_optional_dependency

misplaced optional dependency `rustls-graviola` (remove the `optional` flag and move to `[dev-dependencies]`)

[target.'cfg(windows)'.dependencies]
libc = { workspace = true }
Expand Down Expand Up @@ -382,10 +382,12 @@
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"
comparison_chain = "warn"
doc_link_with_quotes = "warn"
duration_suboptimal_units = "warn"
explicit_deref_methods = "warn"
explicit_into_iter_loop = "warn"
Expand All @@ -397,19 +399,29 @@
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"
large_futures = "warn"
manual_instant_elapsed = "warn"
manual_is_variant_and = "warn"
map_unwrap_or = "warn"
match_bool = "warn"
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"
6 changes: 3 additions & 3 deletions crates/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 2 additions & 6 deletions crates/host_env/src/ctypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
}
Expand Down
2 changes: 1 addition & 1 deletion crates/host_env/src/overlapped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
2 changes: 1 addition & 1 deletion crates/stdlib/src/ssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
};

Expand Down
7 changes: 1 addition & 6 deletions crates/vm/src/builtins/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,12 +406,7 @@ impl Py<PyRange> {
#[pymethod]
fn count(&self, item: PyObjectRef, vm: &VirtualMachine) -> PyResult<usize> {
if let Ok(int) = item.clone().downcast::<PyInt>() {
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.
Expand Down
5 changes: 4 additions & 1 deletion crates/vm/src/stdlib/_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,14 +512,17 @@ pub(crate) fn parse_func_type(
fn type_ignores_from_source(vm: &VirtualMachine, source: &str) -> Vec<PyObjectRef> {
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
Expand Down
6 changes: 1 addition & 5 deletions crates/vm/src/stdlib/_ctypes/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions crates/vm/src/warn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<PyObjectRef> {
if let Some(action) = get_warnings_attr(vm, identifier!(&vm.ctx, defaultaction), false) {
Expand All @@ -164,7 +164,7 @@ fn get_default_action(vm: &VirtualMachine) -> PyResult<PyObjectRef> {
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<PyObjectRef> {
if let Some(registry) = get_warnings_attr(vm, identifier!(&vm.ctx, onceregistry), false) {
Expand Down
Loading