forked from Rust-related/RustPython
Fix some clippy lints that were 'allow'ed
This commit is contained in:
@@ -741,7 +741,6 @@ impl SymbolTableBuilder {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(clippy::single_match)]
|
||||
fn register_name(&mut self, name: &str, role: SymbolUsage) -> SymbolTableResult {
|
||||
let scope_depth = self.tables.len();
|
||||
let table = self.tables.last_mut().unwrap();
|
||||
@@ -777,13 +776,11 @@ impl SymbolTableBuilder {
|
||||
|
||||
// Some more checks:
|
||||
match role {
|
||||
SymbolUsage::Nonlocal => {
|
||||
if scope_depth < 2 {
|
||||
return Err(SymbolTableError {
|
||||
error: format!("cannot define nonlocal '{}' at top level.", name),
|
||||
location,
|
||||
});
|
||||
}
|
||||
SymbolUsage::Nonlocal if scope_depth < 2 => {
|
||||
return Err(SymbolTableError {
|
||||
error: format!("cannot define nonlocal '{}' at top level.", name),
|
||||
location,
|
||||
})
|
||||
}
|
||||
_ => {
|
||||
// Ok!
|
||||
|
||||
@@ -6,7 +6,6 @@ use crate::error::{LexicalError, LexicalErrorType};
|
||||
type ParameterDefs = (Vec<ast::Parameter>, Vec<ast::Expression>);
|
||||
type ParameterDef = (ast::Parameter, Option<ast::Expression>);
|
||||
|
||||
#[allow(clippy::collapsible_if)]
|
||||
pub fn parse_params(
|
||||
params: (Vec<ParameterDef>, Vec<ParameterDef>),
|
||||
) -> Result<ParameterDefs, LexicalError> {
|
||||
@@ -16,15 +15,13 @@ pub fn parse_params(
|
||||
let mut try_default = |name: &ast::Parameter, default| {
|
||||
if let Some(default) = default {
|
||||
defaults.push(default);
|
||||
} else {
|
||||
if !defaults.is_empty() {
|
||||
// Once we have started with defaults, all remaining arguments must
|
||||
// have defaults
|
||||
return Err(LexicalError {
|
||||
error: LexicalErrorType::DefaultArgumentError,
|
||||
location: name.location,
|
||||
});
|
||||
}
|
||||
} else if !defaults.is_empty() {
|
||||
// Once we have started with defaults, all remaining arguments must
|
||||
// have defaults
|
||||
return Err(LexicalError {
|
||||
error: LexicalErrorType::DefaultArgumentError,
|
||||
location: name.location,
|
||||
});
|
||||
}
|
||||
Ok(())
|
||||
};
|
||||
|
||||
@@ -6,11 +6,7 @@
|
||||
//! - Base objects
|
||||
|
||||
// for methods like vm.to_str(), not the typical use of 'to' as a method prefix
|
||||
#![allow(
|
||||
clippy::wrong_self_convention,
|
||||
clippy::let_and_return,
|
||||
clippy::implicit_hasher
|
||||
)]
|
||||
#![allow(clippy::wrong_self_convention, clippy::implicit_hasher)]
|
||||
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustPython/RustPython/master/logo.png")]
|
||||
#![doc(html_root_url = "https://docs.rs/rustpython-vm/")]
|
||||
|
||||
|
||||
@@ -45,8 +45,7 @@ impl PyValue for PyCode {
|
||||
#[pyimpl]
|
||||
impl PyCodeRef {
|
||||
#[pyslot]
|
||||
#[allow(clippy::new_ret_no_self)]
|
||||
fn new(_cls: PyClassRef, vm: &VirtualMachine) -> PyResult {
|
||||
fn new(_cls: PyClassRef, vm: &VirtualMachine) -> PyResult<PyRef<Self>> {
|
||||
Err(vm.new_type_error("Cannot directly create code object".to_owned()))
|
||||
}
|
||||
|
||||
|
||||
@@ -118,7 +118,6 @@ impl_try_from_object_int!(
|
||||
(u64, to_u64),
|
||||
);
|
||||
|
||||
#[allow(clippy::collapsible_if)]
|
||||
fn inner_pow(int1: &BigInt, int2: &BigInt, vm: &VirtualMachine) -> PyResult {
|
||||
if int2.is_negative() {
|
||||
let v1 = try_float(int1, vm)?;
|
||||
|
||||
@@ -73,7 +73,6 @@ struct PropertyArgs {
|
||||
}
|
||||
|
||||
impl SlotDescriptor for PyProperty {
|
||||
#[allow(clippy::collapsible_if)]
|
||||
fn descr_get(
|
||||
vm: &VirtualMachine,
|
||||
zelf: PyObjectRef,
|
||||
@@ -83,12 +82,10 @@ impl SlotDescriptor for PyProperty {
|
||||
let (zelf, obj) = Self::_unwrap(zelf, obj, vm)?;
|
||||
if vm.is_none(&obj) {
|
||||
Ok(zelf.into_object())
|
||||
} else if let Some(getter) = zelf.getter.as_ref() {
|
||||
vm.invoke(&getter, obj)
|
||||
} else {
|
||||
if let Some(getter) = zelf.getter.as_ref() {
|
||||
vm.invoke(&getter, obj)
|
||||
} else {
|
||||
Err(vm.new_attribute_error("unreadable attribute".to_string()))
|
||||
}
|
||||
Err(vm.new_attribute_error("unreadable attribute".to_string()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ fn imp_fix_co_filename(_code: PyObjectRef, _path: PyStringRef) {
|
||||
|
||||
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
|
||||
let ctx = &vm.ctx;
|
||||
let module = py_module!(vm, "_imp", {
|
||||
py_module!(vm, "_imp", {
|
||||
"extension_suffixes" => ctx.new_function(imp_extension_suffixes),
|
||||
"acquire_lock" => ctx.new_function(imp_acquire_lock),
|
||||
"release_lock" => ctx.new_function(imp_release_lock),
|
||||
@@ -99,7 +99,5 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
|
||||
"init_frozen" => ctx.new_function(imp_init_frozen),
|
||||
"is_frozen_package" => ctx.new_function(imp_is_frozen_package),
|
||||
"_fix_co_filename" => ctx.new_function(imp_fix_co_filename),
|
||||
});
|
||||
|
||||
module
|
||||
})
|
||||
}
|
||||
|
||||
@@ -925,7 +925,7 @@ pub fn io_open(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
_ => unimplemented!("'a' mode is not yet implemented"),
|
||||
};
|
||||
|
||||
let io_obj = match typ.chars().next().unwrap() {
|
||||
match typ.chars().next().unwrap() {
|
||||
// If the mode is text this buffer type is consumed on construction of
|
||||
// a TextIOWrapper which is subsequently returned.
|
||||
't' => {
|
||||
@@ -937,8 +937,7 @@ pub fn io_open(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
// For Buffered class construct "raw" IO class e.g. FileIO and pass this into corresponding field
|
||||
'b' => buffered,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
io_obj
|
||||
}
|
||||
}
|
||||
|
||||
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
|
||||
|
||||
@@ -767,6 +767,8 @@ impl PyItertoolsTee {
|
||||
.into_object())
|
||||
}
|
||||
|
||||
// TODO: make tee() a function, rename this class to itertools._tee and make
|
||||
// teedata a python class
|
||||
#[pyslot]
|
||||
#[allow(clippy::new_ret_no_self)]
|
||||
fn tp_new(
|
||||
|
||||
@@ -34,9 +34,7 @@ fn warnings_warn(args: WarnArgs, vm: &VirtualMachine) -> PyResult<()> {
|
||||
|
||||
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
|
||||
let ctx = &vm.ctx;
|
||||
let module = py_module!(vm, "_warnings", {
|
||||
py_module!(vm, "_warnings", {
|
||||
"warn" => ctx.new_function(warnings_warn),
|
||||
});
|
||||
|
||||
module
|
||||
})
|
||||
}
|
||||
|
||||
@@ -102,9 +102,8 @@ fn get_git_timestamp_datetime() -> DateTime<Local> {
|
||||
let timestamp = timestamp.parse::<u64>().unwrap_or(0);
|
||||
|
||||
let datetime = UNIX_EPOCH + Duration::from_secs(timestamp);
|
||||
let datetime = DateTime::<Local>::from(datetime);
|
||||
|
||||
datetime
|
||||
datetime.into()
|
||||
}
|
||||
|
||||
pub fn get_git_date() -> String {
|
||||
|
||||
@@ -768,8 +768,7 @@ impl VirtualMachine {
|
||||
self.trace_event(TraceEvent::Return)?;
|
||||
result
|
||||
} else if class.has_attr("__call__") {
|
||||
let result = self.call_method(&callable, "__call__", args);
|
||||
result
|
||||
self.call_method(&callable, "__call__", args)
|
||||
} else {
|
||||
Err(self.new_type_error(format!(
|
||||
"'{}' object is not callable",
|
||||
@@ -783,8 +782,7 @@ impl VirtualMachine {
|
||||
where
|
||||
T: Into<PyFuncArgs>,
|
||||
{
|
||||
let res = self._invoke(func_ref, args.into());
|
||||
res
|
||||
self._invoke(func_ref, args.into())
|
||||
}
|
||||
|
||||
/// Call registered trace function.
|
||||
|
||||
Reference in New Issue
Block a user