forked from Rust-related/RustPython
Enable rust2024-incompatible pat and keyword-ident lints
This commit is contained in:
@@ -28,7 +28,7 @@ pub enum IterStatus<T> {
|
||||
unsafe impl<T: Traverse> Traverse for IterStatus<T> {
|
||||
fn traverse(&self, tracer_fn: &mut TraverseFn) {
|
||||
match self {
|
||||
IterStatus::Active(ref r) => r.traverse(tracer_fn),
|
||||
IterStatus::Active(r) => r.traverse(tracer_fn),
|
||||
IterStatus::Exhausted => (),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ enum MappingProxyInner {
|
||||
unsafe impl Traverse for MappingProxyInner {
|
||||
fn traverse(&self, tracer_fn: &mut TraverseFn) {
|
||||
match self {
|
||||
MappingProxyInner::Class(ref r) => r.traverse(tracer_fn),
|
||||
MappingProxyInner::Mapping(ref arg) => arg.traverse(tracer_fn),
|
||||
MappingProxyInner::Class(r) => r.traverse(tracer_fn),
|
||||
MappingProxyInner::Mapping(arg) => arg.traverse(tracer_fn),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ pub struct Coro {
|
||||
exception: PyMutex<Option<PyBaseExceptionRef>>, // exc_state
|
||||
}
|
||||
|
||||
fn gen_name(gen: &PyObject, vm: &VirtualMachine) -> &'static str {
|
||||
let typ = gen.class();
|
||||
fn gen_name(jen: &PyObject, vm: &VirtualMachine) -> &'static str {
|
||||
let typ = jen.class();
|
||||
if typ.is(vm.ctx.types.coroutine_type) {
|
||||
"coroutine"
|
||||
} else if typ.is(vm.ctx.types.async_generator) {
|
||||
@@ -67,7 +67,7 @@ impl Coro {
|
||||
|
||||
fn run_with_context<F>(
|
||||
&self,
|
||||
gen: &PyObject,
|
||||
jen: &PyObject,
|
||||
vm: &VirtualMachine,
|
||||
func: F,
|
||||
) -> PyResult<ExecutionResult>
|
||||
@@ -75,7 +75,7 @@ impl Coro {
|
||||
F: FnOnce(FrameRef) -> PyResult<ExecutionResult>,
|
||||
{
|
||||
if self.running.compare_exchange(false, true).is_err() {
|
||||
return Err(vm.new_value_error(format!("{} already executing", gen_name(gen, vm))));
|
||||
return Err(vm.new_value_error(format!("{} already executing", gen_name(jen, vm))));
|
||||
}
|
||||
|
||||
vm.push_exception(self.exception.lock().take());
|
||||
@@ -90,7 +90,7 @@ impl Coro {
|
||||
|
||||
pub fn send(
|
||||
&self,
|
||||
gen: &PyObject,
|
||||
jen: &PyObject,
|
||||
value: PyObjectRef,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<PyIterReturn> {
|
||||
@@ -102,22 +102,22 @@ impl Coro {
|
||||
} else if !vm.is_none(&value) {
|
||||
return Err(vm.new_type_error(format!(
|
||||
"can't send non-None value to a just-started {}",
|
||||
gen_name(gen, vm),
|
||||
gen_name(jen, vm),
|
||||
)));
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let result = self.run_with_context(gen, vm, |f| f.resume(value, vm));
|
||||
let result = self.run_with_context(jen, vm, |f| f.resume(value, vm));
|
||||
self.maybe_close(&result);
|
||||
match result {
|
||||
Ok(exec_res) => Ok(exec_res.into_iter_return(vm)),
|
||||
Err(e) => {
|
||||
if e.fast_isinstance(vm.ctx.exceptions.stop_iteration) {
|
||||
let err =
|
||||
vm.new_runtime_error(format!("{} raised StopIteration", gen_name(gen, vm)));
|
||||
vm.new_runtime_error(format!("{} raised StopIteration", gen_name(jen, vm)));
|
||||
err.set_cause(Some(e));
|
||||
Err(err)
|
||||
} else if gen.class().is(vm.ctx.types.async_generator)
|
||||
} else if jen.class().is(vm.ctx.types.async_generator)
|
||||
&& e.fast_isinstance(vm.ctx.exceptions.stop_async_iteration)
|
||||
{
|
||||
let err = vm
|
||||
@@ -132,7 +132,7 @@ impl Coro {
|
||||
}
|
||||
pub fn throw(
|
||||
&self,
|
||||
gen: &PyObject,
|
||||
jen: &PyObject,
|
||||
exc_type: PyObjectRef,
|
||||
exc_val: PyObjectRef,
|
||||
exc_tb: PyObjectRef,
|
||||
@@ -141,16 +141,16 @@ impl Coro {
|
||||
if self.closed.load() {
|
||||
return Err(vm.normalize_exception(exc_type, exc_val, exc_tb)?);
|
||||
}
|
||||
let result = self.run_with_context(gen, vm, |f| f.gen_throw(vm, exc_type, exc_val, exc_tb));
|
||||
let result = self.run_with_context(jen, vm, |f| f.gen_throw(vm, exc_type, exc_val, exc_tb));
|
||||
self.maybe_close(&result);
|
||||
Ok(result?.into_iter_return(vm))
|
||||
}
|
||||
|
||||
pub fn close(&self, gen: &PyObject, vm: &VirtualMachine) -> PyResult<()> {
|
||||
pub fn close(&self, jen: &PyObject, vm: &VirtualMachine) -> PyResult<()> {
|
||||
if self.closed.load() {
|
||||
return Ok(());
|
||||
}
|
||||
let result = self.run_with_context(gen, vm, |f| {
|
||||
let result = self.run_with_context(jen, vm, |f| {
|
||||
f.gen_throw(
|
||||
vm,
|
||||
vm.ctx.exceptions.generator_exit.to_owned().into(),
|
||||
@@ -161,7 +161,7 @@ impl Coro {
|
||||
self.closed.store(true);
|
||||
match result {
|
||||
Ok(ExecutionResult::Yield(_)) => {
|
||||
Err(vm.new_runtime_error(format!("{} ignored GeneratorExit", gen_name(gen, vm))))
|
||||
Err(vm.new_runtime_error(format!("{} ignored GeneratorExit", gen_name(jen, vm))))
|
||||
}
|
||||
Err(e) if !is_gen_exit(&e, vm) => Err(e),
|
||||
_ => Ok(()),
|
||||
@@ -183,10 +183,10 @@ impl Coro {
|
||||
pub fn set_name(&self, name: PyStrRef) {
|
||||
*self.name.lock() = name;
|
||||
}
|
||||
pub fn repr(&self, gen: &PyObject, id: usize, vm: &VirtualMachine) -> String {
|
||||
pub fn repr(&self, jen: &PyObject, id: usize, vm: &VirtualMachine) -> String {
|
||||
format!(
|
||||
"<{} object {} at {:#x}>",
|
||||
gen_name(gen, vm),
|
||||
gen_name(jen, vm),
|
||||
self.name.lock(),
|
||||
id
|
||||
)
|
||||
|
||||
@@ -426,19 +426,19 @@ impl ExecutingFrame<'_> {
|
||||
exc_val: PyObjectRef,
|
||||
exc_tb: PyObjectRef,
|
||||
) -> PyResult<ExecutionResult> {
|
||||
if let Some(gen) = self.yield_from_target() {
|
||||
if let Some(jen) = self.yield_from_target() {
|
||||
// borrow checker shenanigans - we only need to use exc_type/val/tb if the following
|
||||
// variable is Some
|
||||
let thrower = if let Some(coro) = self.builtin_coro(gen) {
|
||||
let thrower = if let Some(coro) = self.builtin_coro(jen) {
|
||||
Some(Either::A(coro))
|
||||
} else {
|
||||
vm.get_attribute_opt(gen.to_owned(), "throw")?
|
||||
vm.get_attribute_opt(jen.to_owned(), "throw")?
|
||||
.map(Either::B)
|
||||
};
|
||||
if let Some(thrower) = thrower {
|
||||
let ret = match thrower {
|
||||
Either::A(coro) => coro
|
||||
.throw(gen, exc_type, exc_val, exc_tb, vm)
|
||||
.throw(jen, exc_type, exc_val, exc_tb, vm)
|
||||
.to_pyresult(vm), // FIXME:
|
||||
Either::B(meth) => meth.call((exc_type, exc_val, exc_tb), vm),
|
||||
};
|
||||
@@ -1568,16 +1568,16 @@ impl ExecutingFrame<'_> {
|
||||
|
||||
fn _send(
|
||||
&self,
|
||||
gen: &PyObject,
|
||||
jen: &PyObject,
|
||||
val: PyObjectRef,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<PyIterReturn> {
|
||||
match self.builtin_coro(gen) {
|
||||
Some(coro) => coro.send(gen, val, vm),
|
||||
match self.builtin_coro(jen) {
|
||||
Some(coro) => coro.send(jen, val, vm),
|
||||
// FIXME: turn return type to PyResult<PyIterReturn> then ExecutionResult will be simplified
|
||||
None if vm.is_none(&val) => PyIter::new(gen).next(vm),
|
||||
None if vm.is_none(&val) => PyIter::new(jen).next(vm),
|
||||
None => {
|
||||
let meth = gen.get_attr("send", vm)?;
|
||||
let meth = jen.get_attr("send", vm)?;
|
||||
PyIterReturn::from_pyresult(meth.call((val,), vm), vm)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -497,7 +497,7 @@ where
|
||||
{
|
||||
fn traverse(&self, tracer_fn: &mut TraverseFn) {
|
||||
match self {
|
||||
OptionalArg::Present(ref o) => o.traverse(tracer_fn),
|
||||
OptionalArg::Present(o) => o.traverse(tracer_fn),
|
||||
OptionalArg::Missing => (),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//! This module makes use of the parser logic, and translates all ast nodes
|
||||
//! into python ast.AST objects.
|
||||
|
||||
mod gen;
|
||||
mod r#gen;
|
||||
|
||||
use crate::{
|
||||
builtins::{self, PyDict, PyModule, PyStrRef, PyType},
|
||||
@@ -398,6 +398,6 @@ pub const PY_COMPILE_FLAGS_MASK: i32 = PY_COMPILE_FLAG_AST_ONLY
|
||||
|
||||
pub fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
|
||||
let module = _ast::make_module(vm);
|
||||
gen::extend_module_nodes(vm, &module);
|
||||
r#gen::extend_module_nodes(vm, &module);
|
||||
module
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ impl Constructor for PyCSimple {
|
||||
let attributes = cls.get_attributes();
|
||||
let _type_ = attributes
|
||||
.iter()
|
||||
.find(|(&k, _)| k.to_object().str(vm).unwrap().to_string() == *"_type_")
|
||||
.find(|(k, _)| k.to_object().str(vm).unwrap().to_string() == *"_type_")
|
||||
.unwrap()
|
||||
.1
|
||||
.str(vm)?
|
||||
|
||||
@@ -380,8 +380,8 @@ pub(super) mod _os {
|
||||
|
||||
fn env_bytes_as_bytes(obj: &Either<PyStrRef, PyBytesRef>) -> &[u8] {
|
||||
match obj {
|
||||
Either::A(ref s) => s.as_str().as_bytes(),
|
||||
Either::B(ref b) => b.as_bytes(),
|
||||
Either::A(s) => s.as_str().as_bytes(),
|
||||
Either::B(b) => b.as_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user