Skip to content

Commit 9b3fa53

Browse files
authored
Merge pull request RustPython#1843 from RustPython/coolreader18/clippy-fixes
Fix some clippy lints that were previously 'allow'ed
2 parents d3449ae + 97b0788 commit 9b3fa53

File tree

13 files changed

+32
-54
lines changed

13 files changed

+32
-54
lines changed

Lib/types.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ async def _c(): pass
2424
CoroutineType = type(_c)
2525
_c.close() # Prevent ResourceWarning
2626

27-
# XXX RUSTPYTHON TODO: async generators
28-
# async def _ag():
29-
# yield
30-
# _ag = _ag()
31-
# AsyncGeneratorType = type(_ag)
27+
async def _ag():
28+
yield
29+
_ag = _ag()
30+
AsyncGeneratorType = type(_ag)
3231

3332
class _C:
3433
def _m(self): pass

compiler/src/symboltable.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,6 @@ impl SymbolTableBuilder {
739739
Ok(())
740740
}
741741

742-
#[allow(clippy::single_match)]
743742
fn register_name(&mut self, name: &str, role: SymbolUsage) -> SymbolTableResult {
744743
let scope_depth = self.tables.len();
745744
let table = self.tables.last_mut().unwrap();
@@ -775,13 +774,11 @@ impl SymbolTableBuilder {
775774

776775
// Some more checks:
777776
match role {
778-
SymbolUsage::Nonlocal => {
779-
if scope_depth < 2 {
780-
return Err(SymbolTableError {
781-
error: format!("cannot define nonlocal '{}' at top level.", name),
782-
location,
783-
});
784-
}
777+
SymbolUsage::Nonlocal if scope_depth < 2 => {
778+
return Err(SymbolTableError {
779+
error: format!("cannot define nonlocal '{}' at top level.", name),
780+
location,
781+
})
785782
}
786783
_ => {
787784
// Ok!

parser/src/function.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::error::{LexicalError, LexicalErrorType};
66
type ParameterDefs = (Vec<ast::Parameter>, Vec<ast::Expression>);
77
type ParameterDef = (ast::Parameter, Option<ast::Expression>);
88

9-
#[allow(clippy::collapsible_if)]
109
pub fn parse_params(
1110
params: (Vec<ParameterDef>, Vec<ParameterDef>),
1211
) -> Result<ParameterDefs, LexicalError> {
@@ -16,15 +15,13 @@ pub fn parse_params(
1615
let mut try_default = |name: &ast::Parameter, default| {
1716
if let Some(default) = default {
1817
defaults.push(default);
19-
} else {
20-
if !defaults.is_empty() {
21-
// Once we have started with defaults, all remaining arguments must
22-
// have defaults
23-
return Err(LexicalError {
24-
error: LexicalErrorType::DefaultArgumentError,
25-
location: name.location,
26-
});
27-
}
18+
} else if !defaults.is_empty() {
19+
// Once we have started with defaults, all remaining arguments must
20+
// have defaults
21+
return Err(LexicalError {
22+
error: LexicalErrorType::DefaultArgumentError,
23+
location: name.location,
24+
});
2825
}
2926
Ok(())
3027
};

vm/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
//! - Base objects
77
88
// for methods like vm.to_str(), not the typical use of 'to' as a method prefix
9-
#![allow(
10-
clippy::wrong_self_convention,
11-
clippy::let_and_return,
12-
clippy::implicit_hasher
13-
)]
9+
#![allow(clippy::wrong_self_convention, clippy::implicit_hasher)]
1410
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustPython/RustPython/master/logo.png")]
1511
#![doc(html_root_url = "https://docs.rs/rustpython-vm/")]
1612

vm/src/obj/objcode.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ impl PyValue for PyCode {
4949
#[pyimpl]
5050
impl PyCodeRef {
5151
#[pyslot]
52-
#[allow(clippy::new_ret_no_self)]
53-
fn new(_cls: PyClassRef, vm: &VirtualMachine) -> PyResult {
52+
fn new(_cls: PyClassRef, vm: &VirtualMachine) -> PyResult<PyRef<Self>> {
5453
Err(vm.new_type_error("Cannot directly create code object".to_owned()))
5554
}
5655

vm/src/obj/objint.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ impl_try_from_object_int!(
120120
(u64, to_u64),
121121
);
122122

123-
#[allow(clippy::collapsible_if)]
124123
fn inner_pow(int1: &BigInt, int2: &BigInt, vm: &VirtualMachine) -> PyResult {
125124
if int2.is_negative() {
126125
let v1 = try_float(int1, vm)?;

vm/src/obj/objproperty.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ struct PropertyArgs {
7575
}
7676

7777
impl SlotDescriptor for PyProperty {
78-
#[allow(clippy::collapsible_if)]
7978
fn descr_get(
8079
vm: &VirtualMachine,
8180
zelf: PyObjectRef,
@@ -85,12 +84,10 @@ impl SlotDescriptor for PyProperty {
8584
let (zelf, obj) = Self::_unwrap(zelf, obj, vm)?;
8685
if vm.is_none(&obj) {
8786
Ok(zelf.into_object())
87+
} else if let Some(getter) = zelf.getter.as_ref() {
88+
vm.invoke(&getter, obj)
8889
} else {
89-
if let Some(getter) = zelf.getter.as_ref() {
90-
vm.invoke(&getter, obj)
91-
} else {
92-
Err(vm.new_attribute_error("unreadable attribute".to_string()))
93-
}
90+
Err(vm.new_attribute_error("unreadable attribute".to_string()))
9491
}
9592
}
9693
}

vm/src/stdlib/imp.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn imp_fix_co_filename(_code: PyObjectRef, _path: PyStringRef) {
8686

8787
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
8888
let ctx = &vm.ctx;
89-
let module = py_module!(vm, "_imp", {
89+
py_module!(vm, "_imp", {
9090
"extension_suffixes" => ctx.new_function(imp_extension_suffixes),
9191
"acquire_lock" => ctx.new_function(imp_acquire_lock),
9292
"release_lock" => ctx.new_function(imp_release_lock),
@@ -99,7 +99,5 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
9999
"init_frozen" => ctx.new_function(imp_init_frozen),
100100
"is_frozen_package" => ctx.new_function(imp_is_frozen_package),
101101
"_fix_co_filename" => ctx.new_function(imp_fix_co_filename),
102-
});
103-
104-
module
102+
})
105103
}

vm/src/stdlib/io.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ pub fn io_open(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
911911
_ => unimplemented!("'a' mode is not yet implemented"),
912912
};
913913

914-
let io_obj = match typ.chars().next().unwrap() {
914+
match typ.chars().next().unwrap() {
915915
// If the mode is text this buffer type is consumed on construction of
916916
// a TextIOWrapper which is subsequently returned.
917917
't' => {
@@ -923,8 +923,7 @@ pub fn io_open(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
923923
// For Buffered class construct "raw" IO class e.g. FileIO and pass this into corresponding field
924924
'b' => buffered,
925925
_ => unreachable!(),
926-
};
927-
io_obj
926+
}
928927
}
929928

930929
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {

vm/src/stdlib/itertools.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,8 @@ impl PyItertoolsTee {
767767
.into_object())
768768
}
769769

770+
// TODO: make tee() a function, rename this class to itertools._tee and make
771+
// teedata a python class
770772
#[pyslot]
771773
#[allow(clippy::new_ret_no_self)]
772774
fn tp_new(

vm/src/stdlib/warnings.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ fn warnings_warn(args: WarnArgs, vm: &VirtualMachine) -> PyResult<()> {
3434

3535
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
3636
let ctx = &vm.ctx;
37-
let module = py_module!(vm, "_warnings", {
37+
py_module!(vm, "_warnings", {
3838
"warn" => ctx.new_function(warnings_warn),
39-
});
40-
41-
module
39+
})
4240
}

vm/src/version.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,8 @@ fn get_git_timestamp_datetime() -> DateTime<Local> {
102102
let timestamp = timestamp.parse::<u64>().unwrap_or(0);
103103

104104
let datetime = UNIX_EPOCH + Duration::from_secs(timestamp);
105-
let datetime = DateTime::<Local>::from(datetime);
106105

107-
datetime
106+
datetime.into()
108107
}
109108

110109
pub fn get_git_date() -> String {

vm/src/vm.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -791,8 +791,7 @@ impl VirtualMachine {
791791
self.trace_event(TraceEvent::Return)?;
792792
result
793793
} else if class.has_attr("__call__") {
794-
let result = self.call_method(&callable, "__call__", args);
795-
result
794+
self.call_method(&callable, "__call__", args)
796795
} else {
797796
Err(self.new_type_error(format!(
798797
"'{}' object is not callable",
@@ -806,8 +805,7 @@ impl VirtualMachine {
806805
where
807806
T: Into<PyFuncArgs>,
808807
{
809-
let res = self._invoke(func_ref, args.into());
810-
res
808+
self._invoke(func_ref, args.into())
811809
}
812810

813811
/// Call registered trace function.

0 commit comments

Comments
 (0)