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
9 changes: 4 additions & 5 deletions Lib/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ async def _c(): pass
CoroutineType = type(_c)
_c.close() # Prevent ResourceWarning

# XXX RUSTPYTHON TODO: async generators
# async def _ag():
# yield
# _ag = _ag()
# AsyncGeneratorType = type(_ag)
async def _ag():
yield
_ag = _ag()
AsyncGeneratorType = type(_ag)

class _C:
def _m(self): pass
Expand Down
13 changes: 5 additions & 8 deletions compiler/src/symboltable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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!
Expand Down
17 changes: 7 additions & 10 deletions parser/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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(())
};
Expand Down
6 changes: 1 addition & 5 deletions vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/")]

Expand Down
3 changes: 1 addition & 2 deletions vm/src/obj/objcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}

Expand Down
1 change: 0 additions & 1 deletion vm/src/obj/objint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
9 changes: 3 additions & 6 deletions vm/src/obj/objproperty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ struct PropertyArgs {
}

impl SlotDescriptor for PyProperty {
#[allow(clippy::collapsible_if)]
fn descr_get(
vm: &VirtualMachine,
zelf: PyObjectRef,
Expand All @@ -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()))
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions vm/src/stdlib/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
})
}
5 changes: 2 additions & 3 deletions vm/src/stdlib/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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' => {
Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions vm/src/stdlib/itertools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 2 additions & 4 deletions vm/src/stdlib/warnings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
3 changes: 1 addition & 2 deletions vm/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 2 additions & 4 deletions vm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These patterns were actually more debugger-friendly than now.
Do we prefer cleaner code than debugger friendly code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, like being able to see the value of result there? I'm not sure, I don't use traditional debuggers that let you step through, but I'd think that there might be some way to see the value of an expression after it executes? I'm not sure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly that use case. I just know this kind of "single expression for one line" or "single side effect for one line" is a traditional recommendation for debugger-friendly code. Because I am not a heavy user of debuggers, probably there must be experts who know better about this problem.

} else {
Err(self.new_type_error(format!(
"'{}' object is not callable",
Expand All @@ -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.
Expand Down