mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 10:44:36 +08:00
More clippy rules (#8123)
* clippy `bool_to_int_with_if` * doc_link_with_quotes * ip_constant * single_char_pattern * windows
This commit is contained in:
1 parent
455e2624ad
commit
63b99b8996
9 files changed
+28
-26
No files matched your search
+12
@@ -382,10 +382,12 @@ 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"
|
||||
comparison_chain = "warn"
|
||||
doc_link_with_quotes = "warn"
|
||||
duration_suboptimal_units = "warn"
|
||||
enum_glob_use = "warn"
|
||||
explicit_deref_methods = "warn"
|
||||
@@ -398,8 +400,11 @@ 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"
|
||||
large_futures = "warn"
|
||||
manual_instant_elapsed = "warn"
|
||||
manual_is_variant_and = "warn"
|
||||
map_unwrap_or = "warn"
|
||||
match_bool = "warn"
|
||||
@@ -408,11 +413,18 @@ 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"
|
||||
ref_option = "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"
|
||||
@@ -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 {
|
||||
|
||||
@@ -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),
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
|
||||
@@ -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(),
|
||||
)
|
||||
};
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<PyObjectRef> {
|
||||
if let Some(action) = get_warnings_attr(vm, identifier!(&vm.ctx, defaultaction), false) {
|
||||
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user