Skip to content

Commit 54589bf

Browse files
authored
Remove some #[allow(clippy::*)] (RustPython#7878)
* Remove some `#[allow(clippy::*)]` * Fix after merge
1 parent 0871bc8 commit 54589bf

12 files changed

Lines changed: 103 additions & 122 deletions

File tree

crates/codegen/src/compile.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5209,7 +5209,7 @@ impl Compiler {
52095209
}
52105210

52115211
// = compiler_function
5212-
#[allow(clippy::too_many_arguments)]
5212+
#[expect(clippy::too_many_arguments, reason = "ignore warning for now")]
52135213
fn compile_function_def(
52145214
&mut self,
52155215
name: &str,
@@ -7083,13 +7083,11 @@ impl Compiler {
70837083
}
70847084

70857085
// Check for overflow (INT_MAX < size - 1)
7086-
if size > (i32::MAX as usize + 1) {
7087-
return Err(self.error(CodegenErrorType::SyntaxError(
7086+
let size = u32::try_from(size).map_err(|_| {
7087+
self.error(CodegenErrorType::SyntaxError(
70887088
"too many sub-patterns in mapping pattern".to_string(),
7089-
)));
7090-
}
7091-
#[allow(clippy::cast_possible_truncation, reason = "checked right before")]
7092-
let size = size as u32;
7089+
))
7090+
})?;
70937091

70947092
// Step 2: If we have keys to match
70957093
if size > 0 {
@@ -9729,7 +9727,7 @@ impl Compiler {
97299727
Ok(())
97309728
}
97319729

9732-
#[allow(clippy::too_many_arguments)]
9730+
#[expect(clippy::too_many_arguments, reason = "ignore warning for now")]
97339731
fn compile_comprehension(
97349732
&mut self,
97359733
name: &str,

crates/stdlib/src/json/machinery.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ static ESCAPE_CHARS: [&str; 0x20] = [
4444
// And which one need to be escaped (1)
4545
// The characters that need escaping are 0x00 to 0x1F, 0x22 ("), 0x5C (\), 0x7F (DEL)
4646
// Non-ASCII unicode characters can be safely included in a JSON string
47-
#[allow(
48-
clippy::unusual_byte_groupings,
49-
reason = "groups of 16 are intentional here"
50-
)]
5147
static NEEDS_ESCAPING_BITSET: [u64; 4] = [
5248
//fedcba9876543210_fedcba9876543210_fedcba9876543210_fedcba9876543210
5349
0b0000000000000000_0000000000000100_1111111111111111_1111111111111111, // 3_2_1_0

crates/vm/src/builtins/dict.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ impl PyDict {
251251
}
252252

253253
// Python dict methods:
254-
#[allow(clippy::len_without_is_empty)]
255254
#[pyclass(
256255
with(
257256
Py,
@@ -929,7 +928,6 @@ macro_rules! dict_view {
929928
}
930929

931930
fn item(vm: &VirtualMachine, key: PyObjectRef, value: PyObjectRef) -> PyObjectRef {
932-
#[allow(clippy::redundant_closure_call)]
933931
$result_fn(vm, key, value)
934932
}
935933

@@ -1005,7 +1003,6 @@ macro_rules! dict_view {
10051003
self.internal.lock().length_hint(|_| self.size.entries_size)
10061004
}
10071005

1008-
#[allow(clippy::redundant_closure_call)]
10091006
#[pymethod]
10101007
fn __reduce__(&self, vm: &VirtualMachine) -> PyTupleRef {
10111008
let iter = builtins_iter(vm);
@@ -1024,7 +1021,6 @@ macro_rules! dict_view {
10241021
impl SelfIter for $iter_name {}
10251022

10261023
impl IterNext for $iter_name {
1027-
#[allow(clippy::redundant_closure_call)]
10281024
fn next(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
10291025
let mut internal = zelf.internal.lock();
10301026
let next = if let IterStatus::Active(dict) = &internal.status {
@@ -1076,7 +1072,6 @@ macro_rules! dict_view {
10761072
}
10771073
}
10781074

1079-
#[allow(clippy::redundant_closure_call)]
10801075
#[pymethod]
10811076
fn __reduce__(&self, vm: &VirtualMachine) -> PyTupleRef {
10821077
let iter = builtins_reversed(vm);
@@ -1103,7 +1098,6 @@ macro_rules! dict_view {
11031098
impl SelfIter for $reverse_iter_name {}
11041099

11051100
impl IterNext for $reverse_iter_name {
1106-
#[allow(clippy::redundant_closure_call)]
11071101
fn next(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
11081102
let mut internal = zelf.internal.lock();
11091103
let next = if let IterStatus::Active(dict) = &internal.status {

crates/vm/src/builtins/list.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ impl PyList {
245245
Self::from(self.borrow_vec().to_vec()).into_ref(&vm.ctx)
246246
}
247247

248-
#[allow(clippy::len_without_is_empty)]
249248
pub fn __len__(&self) -> usize {
250249
self.borrow_vec().len()
251250
}

crates/vm/src/builtins/module.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ impl PyModuleDef {
8282
}
8383
}
8484

85-
#[allow(
86-
clippy::new_without_default,
87-
reason = "avoid a misleading Default implementation"
88-
)]
8985
#[pyclass(module = false, name = "module")]
9086
#[derive(Debug)]
9187
pub struct PyModule {
@@ -112,7 +108,10 @@ pub struct ModuleInitArgs {
112108
}
113109

114110
impl PyModule {
115-
#[allow(clippy::new_without_default)]
111+
#[expect(
112+
clippy::new_without_default,
113+
reason = "avoid a misleading Default implementation"
114+
)]
116115
#[must_use]
117116
pub const fn new() -> Self {
118117
Self {

crates/vm/src/lib.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@
66
//!
77
//! Some stdlib modules are implemented here, but most of them are in the `rustpython-stdlib` module. The
88
9-
// to allow `mod foo {}` in foo.rs; clippy thinks this is a mistake/misunderstanding of
10-
// how `mod` works, but we want this sometimes for pymodule declarations
119
#![deny(clippy::disallowed_methods)]
12-
#![allow(clippy::module_inception)]
13-
// we want to mirror python naming conventions when defining python structs, so that does mean
14-
// uppercase acronyms, e.g. TextIOWrapper instead of TextIoWrapper
15-
#![allow(clippy::upper_case_acronyms)]
10+
#![allow(
11+
clippy::module_inception,
12+
reason = "
13+
to allow `mod foo {}` in foo.rs; clippy thinks this is a mistake/misunderstanding of
14+
how `mod` works, but we want this sometimes for pymodule declarations"
15+
)]
16+
#![allow(
17+
clippy::upper_case_acronyms,
18+
reason = "
19+
we want to mirror python naming conventions when defining python structs, so that does mean
20+
uppercase acronyms, e.g. TextIOWrapper instead of TextIoWrapper"
21+
)]
1622
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustPython/RustPython/main/logo.png")]
1723
#![doc(html_root_url = "https://docs.rs/rustpython-vm/")]
1824

crates/vm/src/sliceable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl<T: Clone> SliceableSequenceMutOp for Vec<T> {
160160
}
161161
}
162162

163-
#[allow(clippy::len_without_is_empty)]
163+
#[expect(clippy::len_without_is_empty, reason = "Doesn't match CPython code")]
164164
pub trait SliceableSequenceOp {
165165
type Item;
166166
type Sliced;

crates/vm/src/stdlib/_ast/pyast.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![allow(clippy::all)]
2-
31
use super::*;
42
use crate::builtins::{PyGenericAlias, PyTuple, PyTupleRef, PyTypeRef, make_union};
53
use crate::common::ascii;

crates/vm/src/stdlib/_ast/statement.rs

Lines changed: 71 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -36,111 +36,99 @@ impl Node for ast::Stmt {
3636
}
3737
}
3838

39-
#[allow(clippy::if_same_then_else)]
39+
#[expect(clippy::if_same_then_else, reason = "Looks better here")]
4040
fn ast_from_object(
41-
_vm: &VirtualMachine,
41+
vm: &VirtualMachine,
4242
source_file: &SourceFile,
43-
_object: PyObjectRef,
43+
object: PyObjectRef,
4444
) -> PyResult<Self> {
45-
let _cls = _object.class();
46-
Ok(if _cls.is(pyast::NodeStmtFunctionDef::static_type()) {
45+
let cls = object.class();
46+
Ok(if cls.is(pyast::NodeStmtFunctionDef::static_type()) {
4747
Self::FunctionDef(ast::StmtFunctionDef::ast_from_object(
48-
_vm,
48+
vm,
4949
source_file,
50-
_object,
50+
object,
5151
)?)
52-
} else if _cls.is(pyast::NodeStmtAsyncFunctionDef::static_type()) {
52+
} else if cls.is(pyast::NodeStmtAsyncFunctionDef::static_type()) {
5353
Self::FunctionDef(ast::StmtFunctionDef::ast_from_object(
54-
_vm,
55-
source_file,
56-
_object,
57-
)?)
58-
} else if _cls.is(pyast::NodeStmtClassDef::static_type()) {
59-
Self::ClassDef(ast::StmtClassDef::ast_from_object(
60-
_vm,
54+
vm,
6155
source_file,
62-
_object,
56+
object,
6357
)?)
64-
} else if _cls.is(pyast::NodeStmtReturn::static_type()) {
65-
Self::Return(ast::StmtReturn::ast_from_object(_vm, source_file, _object)?)
66-
} else if _cls.is(pyast::NodeStmtDelete::static_type()) {
67-
Self::Delete(ast::StmtDelete::ast_from_object(_vm, source_file, _object)?)
68-
} else if _cls.is(pyast::NodeStmtAssign::static_type()) {
69-
Self::Assign(ast::StmtAssign::ast_from_object(_vm, source_file, _object)?)
70-
} else if _cls.is(pyast::NodeStmtTypeAlias::static_type()) {
58+
} else if cls.is(pyast::NodeStmtClassDef::static_type()) {
59+
Self::ClassDef(ast::StmtClassDef::ast_from_object(vm, source_file, object)?)
60+
} else if cls.is(pyast::NodeStmtReturn::static_type()) {
61+
Self::Return(ast::StmtReturn::ast_from_object(vm, source_file, object)?)
62+
} else if cls.is(pyast::NodeStmtDelete::static_type()) {
63+
Self::Delete(ast::StmtDelete::ast_from_object(vm, source_file, object)?)
64+
} else if cls.is(pyast::NodeStmtAssign::static_type()) {
65+
Self::Assign(ast::StmtAssign::ast_from_object(vm, source_file, object)?)
66+
} else if cls.is(pyast::NodeStmtTypeAlias::static_type()) {
7167
Self::TypeAlias(ast::StmtTypeAlias::ast_from_object(
72-
_vm,
68+
vm,
7369
source_file,
74-
_object,
70+
object,
7571
)?)
76-
} else if _cls.is(pyast::NodeStmtAugAssign::static_type()) {
72+
} else if cls.is(pyast::NodeStmtAugAssign::static_type()) {
7773
Self::AugAssign(ast::StmtAugAssign::ast_from_object(
78-
_vm,
74+
vm,
7975
source_file,
80-
_object,
76+
object,
8177
)?)
82-
} else if _cls.is(pyast::NodeStmtAnnAssign::static_type()) {
78+
} else if cls.is(pyast::NodeStmtAnnAssign::static_type()) {
8379
Self::AnnAssign(ast::StmtAnnAssign::ast_from_object(
84-
_vm,
80+
vm,
8581
source_file,
86-
_object,
82+
object,
8783
)?)
88-
} else if _cls.is(pyast::NodeStmtFor::static_type()) {
89-
Self::For(ast::StmtFor::ast_from_object(_vm, source_file, _object)?)
90-
} else if _cls.is(pyast::NodeStmtAsyncFor::static_type()) {
91-
Self::For(ast::StmtFor::ast_from_object(_vm, source_file, _object)?)
92-
} else if _cls.is(pyast::NodeStmtWhile::static_type()) {
93-
Self::While(ast::StmtWhile::ast_from_object(_vm, source_file, _object)?)
94-
} else if _cls.is(pyast::NodeStmtIf::static_type()) {
95-
Self::If(ast::StmtIf::ast_from_object(_vm, source_file, _object)?)
96-
} else if _cls.is(pyast::NodeStmtWith::static_type()) {
97-
Self::With(ast::StmtWith::ast_from_object(_vm, source_file, _object)?)
98-
} else if _cls.is(pyast::NodeStmtAsyncWith::static_type()) {
99-
Self::With(ast::StmtWith::ast_from_object(_vm, source_file, _object)?)
100-
} else if _cls.is(pyast::NodeStmtMatch::static_type()) {
101-
Self::Match(ast::StmtMatch::ast_from_object(_vm, source_file, _object)?)
102-
} else if _cls.is(pyast::NodeStmtRaise::static_type()) {
103-
Self::Raise(ast::StmtRaise::ast_from_object(_vm, source_file, _object)?)
104-
} else if _cls.is(pyast::NodeStmtTry::static_type()) {
105-
Self::Try(ast::StmtTry::ast_from_object(_vm, source_file, _object)?)
106-
} else if _cls.is(pyast::NodeStmtTryStar::static_type()) {
107-
Self::Try(ast::StmtTry::ast_from_object(_vm, source_file, _object)?)
108-
} else if _cls.is(pyast::NodeStmtAssert::static_type()) {
109-
Self::Assert(ast::StmtAssert::ast_from_object(_vm, source_file, _object)?)
110-
} else if _cls.is(pyast::NodeStmtImport::static_type()) {
111-
Self::Import(ast::StmtImport::ast_from_object(_vm, source_file, _object)?)
112-
} else if _cls.is(pyast::NodeStmtImportFrom::static_type()) {
84+
} else if cls.is(pyast::NodeStmtFor::static_type()) {
85+
Self::For(ast::StmtFor::ast_from_object(vm, source_file, object)?)
86+
} else if cls.is(pyast::NodeStmtAsyncFor::static_type()) {
87+
Self::For(ast::StmtFor::ast_from_object(vm, source_file, object)?)
88+
} else if cls.is(pyast::NodeStmtWhile::static_type()) {
89+
Self::While(ast::StmtWhile::ast_from_object(vm, source_file, object)?)
90+
} else if cls.is(pyast::NodeStmtIf::static_type()) {
91+
Self::If(ast::StmtIf::ast_from_object(vm, source_file, object)?)
92+
} else if cls.is(pyast::NodeStmtWith::static_type()) {
93+
Self::With(ast::StmtWith::ast_from_object(vm, source_file, object)?)
94+
} else if cls.is(pyast::NodeStmtAsyncWith::static_type()) {
95+
Self::With(ast::StmtWith::ast_from_object(vm, source_file, object)?)
96+
} else if cls.is(pyast::NodeStmtMatch::static_type()) {
97+
Self::Match(ast::StmtMatch::ast_from_object(vm, source_file, object)?)
98+
} else if cls.is(pyast::NodeStmtRaise::static_type()) {
99+
Self::Raise(ast::StmtRaise::ast_from_object(vm, source_file, object)?)
100+
} else if cls.is(pyast::NodeStmtTry::static_type()) {
101+
Self::Try(ast::StmtTry::ast_from_object(vm, source_file, object)?)
102+
} else if cls.is(pyast::NodeStmtTryStar::static_type()) {
103+
Self::Try(ast::StmtTry::ast_from_object(vm, source_file, object)?)
104+
} else if cls.is(pyast::NodeStmtAssert::static_type()) {
105+
Self::Assert(ast::StmtAssert::ast_from_object(vm, source_file, object)?)
106+
} else if cls.is(pyast::NodeStmtImport::static_type()) {
107+
Self::Import(ast::StmtImport::ast_from_object(vm, source_file, object)?)
108+
} else if cls.is(pyast::NodeStmtImportFrom::static_type()) {
113109
Self::ImportFrom(ast::StmtImportFrom::ast_from_object(
114-
_vm,
115-
source_file,
116-
_object,
117-
)?)
118-
} else if _cls.is(pyast::NodeStmtGlobal::static_type()) {
119-
Self::Global(ast::StmtGlobal::ast_from_object(_vm, source_file, _object)?)
120-
} else if _cls.is(pyast::NodeStmtNonlocal::static_type()) {
121-
Self::Nonlocal(ast::StmtNonlocal::ast_from_object(
122-
_vm,
123-
source_file,
124-
_object,
125-
)?)
126-
} else if _cls.is(pyast::NodeStmtExpr::static_type()) {
127-
Self::Expr(ast::StmtExpr::ast_from_object(_vm, source_file, _object)?)
128-
} else if _cls.is(pyast::NodeStmtPass::static_type()) {
129-
Self::Pass(ast::StmtPass::ast_from_object(_vm, source_file, _object)?)
130-
} else if _cls.is(pyast::NodeStmtBreak::static_type()) {
131-
Self::Break(ast::StmtBreak::ast_from_object(_vm, source_file, _object)?)
132-
} else if _cls.is(pyast::NodeStmtContinue::static_type()) {
133-
Self::Continue(ast::StmtContinue::ast_from_object(
134-
_vm,
110+
vm,
135111
source_file,
136-
_object,
112+
object,
137113
)?)
138-
} else if _vm.is_none(&_object) {
139-
return Err(_vm.new_value_error("None disallowed in statement list"));
114+
} else if cls.is(pyast::NodeStmtGlobal::static_type()) {
115+
Self::Global(ast::StmtGlobal::ast_from_object(vm, source_file, object)?)
116+
} else if cls.is(pyast::NodeStmtNonlocal::static_type()) {
117+
Self::Nonlocal(ast::StmtNonlocal::ast_from_object(vm, source_file, object)?)
118+
} else if cls.is(pyast::NodeStmtExpr::static_type()) {
119+
Self::Expr(ast::StmtExpr::ast_from_object(vm, source_file, object)?)
120+
} else if cls.is(pyast::NodeStmtPass::static_type()) {
121+
Self::Pass(ast::StmtPass::ast_from_object(vm, source_file, object)?)
122+
} else if cls.is(pyast::NodeStmtBreak::static_type()) {
123+
Self::Break(ast::StmtBreak::ast_from_object(vm, source_file, object)?)
124+
} else if cls.is(pyast::NodeStmtContinue::static_type()) {
125+
Self::Continue(ast::StmtContinue::ast_from_object(vm, source_file, object)?)
126+
} else if vm.is_none(&object) {
127+
return Err(vm.new_value_error("None disallowed in statement list"));
140128
} else {
141-
return Err(_vm.new_type_error(format!(
129+
return Err(vm.new_type_error(format!(
142130
"expected some sort of stmt, but got {}",
143-
_object.repr(_vm)?
131+
object.repr(vm)?
144132
)));
145133
})
146134
}
@@ -201,6 +189,7 @@ impl Node for ast::StmtFunctionDef {
201189
node_add_location(&dict, range, vm, source_file);
202190
node.into()
203191
}
192+
204193
fn ast_from_object(
205194
_vm: &VirtualMachine,
206195
source_file: &SourceFile,

crates/vm/src/stdlib/_io.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ mod _io {
147147
use num_traits::ToPrimitive;
148148
use std::io::{self, Cursor, SeekFrom, prelude::*};
149149

150-
#[allow(clippy::let_and_return)]
151150
fn validate_whence(whence: i32) -> bool {
152151
host_io::validate_whence(whence)
153152
}
@@ -204,7 +203,7 @@ mod _io {
204203
))
205204
}
206205

207-
#[derive(FromArgs)]
206+
#[derive(Clone, Copy, FromArgs)]
208207
pub(super) struct OptionalSize {
209208
// In a few functions, the default value is -1 rather than None.
210209
// Make sure the default value doesn't affect compatibility.
@@ -213,7 +212,6 @@ mod _io {
213212
}
214213

215214
impl OptionalSize {
216-
#[allow(clippy::wrong_self_convention)]
217215
pub(super) fn to_usize(self) -> Option<usize> {
218216
self.size?.to_usize()
219217
}
@@ -2907,7 +2905,7 @@ mod _io {
29072905
Ok(())
29082906
}
29092907

2910-
#[allow(clippy::type_complexity)]
2908+
#[expect(clippy::type_complexity, reason = "ignore warning for now")]
29112909
fn find_coder(
29122910
buffer: &PyObject,
29132911
encoding: &str,

0 commit comments

Comments
 (0)