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
75 changes: 42 additions & 33 deletions crates/stdlib/src/_asyncio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ pub(crate) mod _asyncio {

#[derive(FromArgs)]
struct AddDoneCallbackArgs {
#[pyarg(positional, name = "fn")]
func: PyObjectRef,
#[pyarg(positional)]
r#fn: PyObjectRef,
#[pyarg(named, optional)]
context: Option<PyObjectRef>,
}
Expand All @@ -76,8 +76,8 @@ pub(crate) mod _asyncio {

#[derive(FromArgs)]
struct LoopArg {
#[pyarg(any, name = "loop", optional)]
loop_: Option<PyObjectRef>,
#[pyarg(any, optional)]
r#loop: Option<PyObjectRef>,
}

#[derive(FromArgs)]
Expand Down Expand Up @@ -146,15 +146,15 @@ pub(crate) mod _asyncio {

#[derive(FromArgs)]
struct FutureInitArgs {
#[pyarg(named, name = "loop", optional)]
loop_: Option<PyObjectRef>,
#[pyarg(named, optional)]
r#loop: Option<PyObjectRef>,
}

impl Initializer for PyFuture {
type Args = FutureInitArgs;

fn init(zelf: &Py<Self>, args: Self::Args, vm: &VirtualMachine) -> PyResult<()> {
Self::py_init(zelf, args.loop_, vm)
Self::py_init(zelf, args.r#loop, vm)
}
}

Expand Down Expand Up @@ -369,16 +369,16 @@ pub(crate) mod _asyncio {
};

if self.fut_state.load() != FutureState::Pending {
self.call_soon_with_context(owner, args.func, Some(ctx), vm)?;
self.call_soon_with_context(owner, args.r#fn, Some(ctx), vm)?;
} else {
let callbacks = self.fut_callbacks.read().clone();
// Once a list exists, append to it even if callback0 was removed.
// Refilling callback0 would move the new callback ahead of the list.
if callbacks.is_none() && self.fut_callback0.read().is_none() {
*self.fut_callback0.write() = Some(args.func);
*self.fut_callback0.write() = Some(args.r#fn);
*self.fut_context0.write() = Some(ctx);
} else {
let tuple = vm.ctx.new_tuple(vec![args.func, ctx]);
let tuple = vm.ctx.new_tuple(vec![args.r#fn, ctx]);
if let Some(callbacks) = callbacks {
callbacks
.downcast_ref::<PyList>()
Expand All @@ -397,7 +397,7 @@ pub(crate) mod _asyncio {
#[pymethod]
fn remove_done_callback(
zelf: &Py<Self>,
RemoveDoneCallbackArgs { func }: RemoveDoneCallbackArgs,
RemoveDoneCallbackArgs { r#fn: func }: RemoveDoneCallbackArgs,
vm: &VirtualMachine,
) -> PyResult<isize> {
zelf.remove_done_callback_impl(&func, vm)
Expand Down Expand Up @@ -1184,8 +1184,8 @@ pub(crate) mod _asyncio {
struct TaskInitArgs {
#[pyarg(any)]
coro: PyObjectRef,
#[pyarg(named, name = "loop", optional)]
loop_: Option<PyObjectRef>,
#[pyarg(named, optional)]
r#loop: Option<PyObjectRef>,
#[pyarg(named, optional)]
name: Option<PyObjectRef>,
#[pyarg(named, optional)]
Expand Down Expand Up @@ -1244,7 +1244,7 @@ pub(crate) mod _asyncio {
}

// Get the event loop
let loop_obj = match args.loop_ {
let loop_obj = match args.r#loop {
Some(l) => l,
None => get_running_loop(vm)
.map_err(|_| vm.new_runtime_error("no current event loop"))?,
Expand Down Expand Up @@ -1428,7 +1428,7 @@ pub(crate) mod _asyncio {
#[pymethod]
fn remove_done_callback(
zelf: &Py<Self>,
RemoveDoneCallbackArgs { func }: RemoveDoneCallbackArgs,
RemoveDoneCallbackArgs { r#fn: func }: RemoveDoneCallbackArgs,
vm: &VirtualMachine,
) -> PyResult<isize> {
zelf.base.remove_done_callback_impl(&func, vm)
Expand Down Expand Up @@ -1909,7 +1909,7 @@ pub(crate) mod _asyncio {
// Swap current task - save previous task
let prev_task = _swap_current_task(
LoopTaskArgs {
loop_: loop_obj.clone(),
r#loop: loop_obj.clone(),
task: task_obj.clone(),
},
vm,
Expand Down Expand Up @@ -1938,7 +1938,7 @@ pub(crate) mod _asyncio {
.store(false, Ordering::Relaxed);
let _ = _swap_current_task(
LoopTaskArgs {
loop_: loop_obj,
r#loop: loop_obj,
task: prev_task,
},
vm,
Expand Down Expand Up @@ -1970,7 +1970,7 @@ pub(crate) mod _asyncio {
None => {
let _ = _swap_current_task(
LoopTaskArgs {
loop_: loop_obj,
r#loop: loop_obj,
task: prev_task,
},
vm,
Expand All @@ -1983,7 +1983,7 @@ pub(crate) mod _asyncio {
// Restore previous task
let _ = _swap_current_task(
LoopTaskArgs {
loop_: loop_obj,
r#loop: loop_obj,
task: prev_task,
},
vm,
Expand Down Expand Up @@ -2052,7 +2052,7 @@ pub(crate) mod _asyncio {
// Enter task - register as current task
_enter_task(
LoopTaskArgs {
loop_: loop_obj.clone(),
r#loop: loop_obj.clone(),
task: task.to_owned(),
},
vm,
Expand Down Expand Up @@ -2097,7 +2097,7 @@ pub(crate) mod _asyncio {
// Leave task - unregister as current task (must happen even on error)
let _ = _leave_task(
LoopTaskArgs {
loop_: loop_obj,
r#loop: loop_obj,
task: task.to_owned(),
},
vm,
Expand Down Expand Up @@ -2473,13 +2473,13 @@ pub(crate) mod _asyncio {

#[derive(FromArgs)]
struct SetRunningLoopArgs {
#[pyarg(positional, name = "loop")]
loop_: Option<PyObjectRef>,
#[pyarg(positional)]
r#loop: Option<PyObjectRef>,
}

#[pyfunction]
fn _set_running_loop(args: SetRunningLoopArgs, vm: &VirtualMachine) {
*vm.asyncio_running_loop.borrow_mut() = args.loop_;
*vm.asyncio_running_loop.borrow_mut() = args.r#loop;
}

#[pyfunction]
Expand Down Expand Up @@ -2509,7 +2509,7 @@ pub(crate) mod _asyncio {

#[pyfunction]
fn current_task(args: LoopArg, vm: &VirtualMachine) -> PyResult {
let loop_obj = match args.loop_ {
let loop_obj = match args.r#loop {
Some(l) if !vm.is_none(&l) => l,
_ => {
// When loop is None or not provided, use the running loop
Expand Down Expand Up @@ -2552,7 +2552,7 @@ pub(crate) mod _asyncio {

#[pyfunction]
fn all_tasks(args: LoopArg, vm: &VirtualMachine) -> PyResult {
let loop_obj = match args.loop_ {
let loop_obj = match args.r#loop {
Some(l) if !vm.is_none(&l) => l,
_ => get_running_loop(vm)?,
};
Expand Down Expand Up @@ -2593,8 +2593,8 @@ pub(crate) mod _asyncio {

#[derive(FromArgs)]
struct RemoveDoneCallbackArgs {
#[pyarg(positional, name = "fn")]
func: PyObjectRef,
#[pyarg(positional)]
r#fn: PyObjectRef,
}

#[derive(FromArgs)]
Expand All @@ -2605,8 +2605,8 @@ pub(crate) mod _asyncio {

#[derive(FromArgs)]
struct LoopTaskArgs {
#[pyarg(any, name = "loop")]
loop_: PyObjectRef,
#[pyarg(any)]
r#loop: PyObjectRef,
#[pyarg(any)]
task: PyObjectRef,
}
Expand Down Expand Up @@ -2643,7 +2643,10 @@ pub(crate) mod _asyncio {

#[pyfunction]
fn _enter_task(
LoopTaskArgs { loop_, task }: LoopTaskArgs,
LoopTaskArgs {
r#loop: loop_,
task,
}: LoopTaskArgs,
vm: &VirtualMachine,
) -> PyResult<()> {
// Per-thread check, matching CPython's ts->asyncio_running_task
Expand Down Expand Up @@ -2671,7 +2674,10 @@ pub(crate) mod _asyncio {

#[pyfunction]
fn _leave_task(
LoopTaskArgs { loop_, task }: LoopTaskArgs,
LoopTaskArgs {
r#loop: loop_,
task,
}: LoopTaskArgs,
vm: &VirtualMachine,
) -> PyResult<()> {
// Per-thread check, matching CPython's ts->asyncio_running_task
Expand Down Expand Up @@ -2699,7 +2705,10 @@ pub(crate) mod _asyncio {

#[pyfunction]
fn _swap_current_task(
LoopTaskArgs { loop_, task }: LoopTaskArgs,
LoopTaskArgs {
r#loop: loop_,
task,
}: LoopTaskArgs,
vm: &VirtualMachine,
) -> PyObjectRef {
// Per-thread swap, matching CPython's swap_current_task
Expand Down
10 changes: 5 additions & 5 deletions crates/stdlib/src/binascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

mod base_n;

pub(super) use decl::crc32;
pub(super) use decl::crc32_impl;
pub(crate) use decl::module_def;

use rustpython_common::binascii::{Base64DecodeError, Error};
Expand Down Expand Up @@ -218,15 +218,15 @@ mod decl {
crc: ArgIndex,
}

pub(crate) fn crc32(data: ArgBytesLike, crc: ArgIndex) -> u32 {
pub(crate) fn crc32_impl(data: ArgBytesLike, crc: ArgIndex) -> u32 {
let crc = crc.into_int_ref().as_u32_mask();
data.with_ref(|bytes| binascii::crc32(bytes, crc))
}

#[pyfunction(name = "crc32")]
fn crc32_py(args: Crc32Args) -> u32 {
#[pyfunction]
fn crc32(args: Crc32Args) -> u32 {
let Crc32Args { data, crc } = args;
crc32(data, crc)
crc32_impl(data, crc)
}

#[pyfunction]
Expand Down
8 changes: 4 additions & 4 deletions crates/stdlib/src/bz2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ mod _bz2 {
result.map_err(|error| map_bz2_error(error, vm))
}

#[pymethod(name = "__reduce__")]
fn reduce(_zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<()> {
#[pymethod]
fn __reduce__(_zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<()> {
Err(vm.new_type_error("cannot pickle '_bz2.BZ2Decompressor' object"))
}
}
Expand Down Expand Up @@ -167,8 +167,8 @@ mod _bz2 {
compressor.flush().map_err(|error| map_bz2_error(error, vm))
}

#[pymethod(name = "__reduce__")]
fn reduce(_zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<()> {
#[pymethod]
fn __reduce__(_zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<()> {
Err(vm.new_type_error("cannot pickle '_bz2.BZ2Compressor' object"))
}
}
Expand Down
16 changes: 8 additions & 8 deletions crates/stdlib/src/cjkcodecs/multibytecodec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,8 @@ mod _multibytecodec {
// `__create_codec`, which turns the capsule `getcodec` hands it into a
// codec object. Nothing here carries a codec in a capsule, so the argument
// check rejects everything a caller can pass.
#[pyfunction(name = "__create_codec")]
fn create_codec(_arg: PyObjectRef, vm: &VirtualMachine) -> PyResult {
#[pyfunction]
fn __create_codec(_arg: PyObjectRef, vm: &VirtualMachine) -> PyResult {
Err(vm.new_value_error("argument type invalid"))
}

Expand Down Expand Up @@ -679,17 +679,17 @@ mod _multibytecodec {
#[pyarg(any)]
input: PyObjectRef,
// Any object is accepted by truthiness.
#[pyarg(any, name = "final", default = false)]
final_input: PyObjectRef,
#[pyarg(any, default = false)]
r#final: PyObjectRef,
}

#[derive(FromArgs)]
struct IncrementalDecodeArgs {
#[pyarg(any)]
input: ArgBytesLike,
// Any object is accepted by truthiness.
#[pyarg(any, name = "final", default = false)]
final_input: PyObjectRef,
#[pyarg(any, default = false)]
r#final: PyObjectRef,
}

/// The `bool(accept={int})` conversion the `final` arguments share, which
Expand Down Expand Up @@ -753,7 +753,7 @@ mod _multibytecodec {
args: IncrementalEncodeArgs,
vm: &VirtualMachine,
) -> PyResult<PyObjectRef> {
let final_input = final_arg(args.final_input, vm)?;
let final_input = final_arg(args.r#final, vm)?;
// Driven on a detached copy: an error handler can re-enter this object.
let mut local = zelf.inner.lock().clone();
let result = zelf
Expand Down Expand Up @@ -884,7 +884,7 @@ mod _multibytecodec {
args: IncrementalDecodeArgs,
vm: &VirtualMachine,
) -> PyResult<PyStrRef> {
let final_input = final_arg(args.final_input, vm)?;
let final_input = final_arg(args.r#final, vm)?;
// Driven on a detached copy: an error handler can re-enter this object.
let mut local = zelf.inner.lock().clone();
let original_pending = core::mem::take(&mut local.pending);
Expand Down
8 changes: 4 additions & 4 deletions crates/stdlib/src/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ mod _csv {
Some(vm.ctx.new_str(zelf.escapechar?))
}

#[pygetset(name = "strict")]
fn get_strict(zelf: &Py<Self>) -> bool {
#[pygetset]
fn strict(zelf: &Py<Self>) -> bool {
zelf.strict
}
}
Expand Down Expand Up @@ -1062,8 +1062,8 @@ mod _csv {

#[pyclass(flags(DISALLOW_INSTANTIATION))]
impl Writer {
#[pygetset(name = "dialect")]
fn get_dialect(zelf: &Py<Self>, _vm: &VirtualMachine) -> PyDialect {
#[pygetset]
fn dialect(zelf: &Py<Self>, _vm: &VirtualMachine) -> PyDialect {
zelf.dialect.clone()
}

Expand Down
Loading
Loading