Skip to content

Commit fb57e68

Browse files
youknowdotcodex
andauthored
Use canonical names for Python bindings (#9730)
Remove unnecessary method, property, argument and attribute name overrides. Rename internal helpers and callers while preserving exported names, signatures, defaults and intentional aliases. Assisted-by: Codex:model-version-unavailable Co-authored-by: Codex <codex@openai.com>
1 parent 6e606b3 commit fb57e68

46 files changed

Lines changed: 316 additions & 278 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎crates/stdlib/src/_asyncio.rs‎

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ pub(crate) mod _asyncio {
6262

6363
#[derive(FromArgs)]
6464
struct AddDoneCallbackArgs {
65-
#[pyarg(positional, name = "fn")]
66-
func: PyObjectRef,
65+
#[pyarg(positional)]
66+
r#fn: PyObjectRef,
6767
#[pyarg(named, optional)]
6868
context: Option<PyObjectRef>,
6969
}
@@ -76,8 +76,8 @@ pub(crate) mod _asyncio {
7676

7777
#[derive(FromArgs)]
7878
struct LoopArg {
79-
#[pyarg(any, name = "loop", optional)]
80-
loop_: Option<PyObjectRef>,
79+
#[pyarg(any, optional)]
80+
r#loop: Option<PyObjectRef>,
8181
}
8282

8383
#[derive(FromArgs)]
@@ -146,15 +146,15 @@ pub(crate) mod _asyncio {
146146

147147
#[derive(FromArgs)]
148148
struct FutureInitArgs {
149-
#[pyarg(named, name = "loop", optional)]
150-
loop_: Option<PyObjectRef>,
149+
#[pyarg(named, optional)]
150+
r#loop: Option<PyObjectRef>,
151151
}
152152

153153
impl Initializer for PyFuture {
154154
type Args = FutureInitArgs;
155155

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

@@ -369,16 +369,16 @@ pub(crate) mod _asyncio {
369369
};
370370

371371
if self.fut_state.load() != FutureState::Pending {
372-
self.call_soon_with_context(owner, args.func, Some(ctx), vm)?;
372+
self.call_soon_with_context(owner, args.r#fn, Some(ctx), vm)?;
373373
} else {
374374
let callbacks = self.fut_callbacks.read().clone();
375375
// Once a list exists, append to it even if callback0 was removed.
376376
// Refilling callback0 would move the new callback ahead of the list.
377377
if callbacks.is_none() && self.fut_callback0.read().is_none() {
378-
*self.fut_callback0.write() = Some(args.func);
378+
*self.fut_callback0.write() = Some(args.r#fn);
379379
*self.fut_context0.write() = Some(ctx);
380380
} else {
381-
let tuple = vm.ctx.new_tuple(vec![args.func, ctx]);
381+
let tuple = vm.ctx.new_tuple(vec![args.r#fn, ctx]);
382382
if let Some(callbacks) = callbacks {
383383
callbacks
384384
.downcast_ref::<PyList>()
@@ -397,7 +397,7 @@ pub(crate) mod _asyncio {
397397
#[pymethod]
398398
fn remove_done_callback(
399399
zelf: &Py<Self>,
400-
RemoveDoneCallbackArgs { func }: RemoveDoneCallbackArgs,
400+
RemoveDoneCallbackArgs { r#fn: func }: RemoveDoneCallbackArgs,
401401
vm: &VirtualMachine,
402402
) -> PyResult<isize> {
403403
zelf.remove_done_callback_impl(&func, vm)
@@ -1175,8 +1175,8 @@ pub(crate) mod _asyncio {
11751175
struct TaskInitArgs {
11761176
#[pyarg(any)]
11771177
coro: PyObjectRef,
1178-
#[pyarg(named, name = "loop", optional)]
1179-
loop_: Option<PyObjectRef>,
1178+
#[pyarg(named, optional)]
1179+
r#loop: Option<PyObjectRef>,
11801180
#[pyarg(named, optional)]
11811181
name: Option<PyObjectRef>,
11821182
#[pyarg(named, optional)]
@@ -1235,7 +1235,7 @@ pub(crate) mod _asyncio {
12351235
}
12361236

12371237
// Get the event loop
1238-
let loop_obj = match args.loop_ {
1238+
let loop_obj = match args.r#loop {
12391239
Some(l) => l,
12401240
None => get_running_loop(vm)
12411241
.map_err(|_| vm.new_runtime_error("no current event loop"))?,
@@ -1419,7 +1419,7 @@ pub(crate) mod _asyncio {
14191419
#[pymethod]
14201420
fn remove_done_callback(
14211421
zelf: &Py<Self>,
1422-
RemoveDoneCallbackArgs { func }: RemoveDoneCallbackArgs,
1422+
RemoveDoneCallbackArgs { r#fn: func }: RemoveDoneCallbackArgs,
14231423
vm: &VirtualMachine,
14241424
) -> PyResult<isize> {
14251425
zelf.base.remove_done_callback_impl(&func, vm)
@@ -1900,7 +1900,7 @@ pub(crate) mod _asyncio {
19001900
// Swap current task - save previous task
19011901
let prev_task = _swap_current_task(
19021902
LoopTaskArgs {
1903-
loop_: loop_obj.clone(),
1903+
r#loop: loop_obj.clone(),
19041904
task: task_obj.clone(),
19051905
},
19061906
vm,
@@ -1929,7 +1929,7 @@ pub(crate) mod _asyncio {
19291929
.store(false, Ordering::Relaxed);
19301930
let _ = _swap_current_task(
19311931
LoopTaskArgs {
1932-
loop_: loop_obj,
1932+
r#loop: loop_obj,
19331933
task: prev_task,
19341934
},
19351935
vm,
@@ -1961,7 +1961,7 @@ pub(crate) mod _asyncio {
19611961
None => {
19621962
let _ = _swap_current_task(
19631963
LoopTaskArgs {
1964-
loop_: loop_obj,
1964+
r#loop: loop_obj,
19651965
task: prev_task,
19661966
},
19671967
vm,
@@ -1974,7 +1974,7 @@ pub(crate) mod _asyncio {
19741974
// Restore previous task
19751975
let _ = _swap_current_task(
19761976
LoopTaskArgs {
1977-
loop_: loop_obj,
1977+
r#loop: loop_obj,
19781978
task: prev_task,
19791979
},
19801980
vm,
@@ -2043,7 +2043,7 @@ pub(crate) mod _asyncio {
20432043
// Enter task - register as current task
20442044
_enter_task(
20452045
LoopTaskArgs {
2046-
loop_: loop_obj.clone(),
2046+
r#loop: loop_obj.clone(),
20472047
task: task.to_owned(),
20482048
},
20492049
vm,
@@ -2088,7 +2088,7 @@ pub(crate) mod _asyncio {
20882088
// Leave task - unregister as current task (must happen even on error)
20892089
let _ = _leave_task(
20902090
LoopTaskArgs {
2091-
loop_: loop_obj,
2091+
r#loop: loop_obj,
20922092
task: task.to_owned(),
20932093
},
20942094
vm,
@@ -2464,13 +2464,13 @@ pub(crate) mod _asyncio {
24642464

24652465
#[derive(FromArgs)]
24662466
struct SetRunningLoopArgs {
2467-
#[pyarg(positional, name = "loop")]
2468-
loop_: Option<PyObjectRef>,
2467+
#[pyarg(positional)]
2468+
r#loop: Option<PyObjectRef>,
24692469
}
24702470

24712471
#[pyfunction]
24722472
fn _set_running_loop(args: SetRunningLoopArgs, vm: &VirtualMachine) {
2473-
*vm.asyncio_running_loop.borrow_mut() = args.loop_;
2473+
*vm.asyncio_running_loop.borrow_mut() = args.r#loop;
24742474
}
24752475

24762476
#[pyfunction]
@@ -2500,7 +2500,7 @@ pub(crate) mod _asyncio {
25002500

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

25442544
#[pyfunction]
25452545
fn all_tasks(args: LoopArg, vm: &VirtualMachine) -> PyResult {
2546-
let loop_obj = match args.loop_ {
2546+
let loop_obj = match args.r#loop {
25472547
Some(l) if !vm.is_none(&l) => l,
25482548
_ => get_running_loop(vm)?,
25492549
};
@@ -2584,8 +2584,8 @@ pub(crate) mod _asyncio {
25842584

25852585
#[derive(FromArgs)]
25862586
struct RemoveDoneCallbackArgs {
2587-
#[pyarg(positional, name = "fn")]
2588-
func: PyObjectRef,
2587+
#[pyarg(positional)]
2588+
r#fn: PyObjectRef,
25892589
}
25902590

25912591
#[derive(FromArgs)]
@@ -2596,8 +2596,8 @@ pub(crate) mod _asyncio {
25962596

25972597
#[derive(FromArgs)]
25982598
struct LoopTaskArgs {
2599-
#[pyarg(any, name = "loop")]
2600-
loop_: PyObjectRef,
2599+
#[pyarg(any)]
2600+
r#loop: PyObjectRef,
26012601
#[pyarg(any)]
26022602
task: PyObjectRef,
26032603
}
@@ -2634,7 +2634,10 @@ pub(crate) mod _asyncio {
26342634

26352635
#[pyfunction]
26362636
fn _enter_task(
2637-
LoopTaskArgs { loop_, task }: LoopTaskArgs,
2637+
LoopTaskArgs {
2638+
r#loop: loop_,
2639+
task,
2640+
}: LoopTaskArgs,
26382641
vm: &VirtualMachine,
26392642
) -> PyResult<()> {
26402643
// Per-thread check, matching CPython's ts->asyncio_running_task
@@ -2662,7 +2665,10 @@ pub(crate) mod _asyncio {
26622665

26632666
#[pyfunction]
26642667
fn _leave_task(
2665-
LoopTaskArgs { loop_, task }: LoopTaskArgs,
2668+
LoopTaskArgs {
2669+
r#loop: loop_,
2670+
task,
2671+
}: LoopTaskArgs,
26662672
vm: &VirtualMachine,
26672673
) -> PyResult<()> {
26682674
// Per-thread check, matching CPython's ts->asyncio_running_task
@@ -2690,7 +2696,10 @@ pub(crate) mod _asyncio {
26902696

26912697
#[pyfunction]
26922698
fn _swap_current_task(
2693-
LoopTaskArgs { loop_, task }: LoopTaskArgs,
2699+
LoopTaskArgs {
2700+
r#loop: loop_,
2701+
task,
2702+
}: LoopTaskArgs,
26942703
vm: &VirtualMachine,
26952704
) -> PyObjectRef {
26962705
// Per-thread swap, matching CPython's swap_current_task

‎crates/stdlib/src/binascii.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
mod base_n;
44

5-
pub(super) use decl::crc32;
5+
pub(super) use decl::crc32_impl;
66
pub(crate) use decl::module_def;
77

88
use rustpython_common::binascii::{Base64DecodeError, Error};
@@ -218,15 +218,15 @@ mod decl {
218218
crc: ArgIndex,
219219
}
220220

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

226-
#[pyfunction(name = "crc32")]
227-
fn crc32_py(args: Crc32Args) -> u32 {
226+
#[pyfunction]
227+
fn crc32(args: Crc32Args) -> u32 {
228228
let Crc32Args { data, crc } = args;
229-
crc32(data, crc)
229+
crc32_impl(data, crc)
230230
}
231231

232232
#[pyfunction]

‎crates/stdlib/src/bz2.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ mod _bz2 {
105105
result.map_err(|error| map_bz2_error(error, vm))
106106
}
107107

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

170-
#[pymethod(name = "__reduce__")]
171-
fn reduce(_zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<()> {
170+
#[pymethod]
171+
fn __reduce__(_zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<()> {
172172
Err(vm.new_type_error("cannot pickle '_bz2.BZ2Compressor' object"))
173173
}
174174
}

‎crates/stdlib/src/cjkcodecs/multibytecodec.rs‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,8 @@ mod _multibytecodec {
617617
// `__create_codec`, which turns the capsule `getcodec` hands it into a
618618
// codec object. Nothing here carries a codec in a capsule, so the argument
619619
// check rejects everything a caller can pass.
620-
#[pyfunction(name = "__create_codec")]
621-
fn create_codec(_arg: PyObjectRef, vm: &VirtualMachine) -> PyResult {
620+
#[pyfunction]
621+
fn __create_codec(_arg: PyObjectRef, vm: &VirtualMachine) -> PyResult {
622622
Err(vm.new_value_error("argument type invalid"))
623623
}
624624

@@ -679,17 +679,17 @@ mod _multibytecodec {
679679
#[pyarg(any)]
680680
input: PyObjectRef,
681681
// Any object is accepted by truthiness.
682-
#[pyarg(any, name = "final", default = false)]
683-
final_input: PyObjectRef,
682+
#[pyarg(any, default = false)]
683+
r#final: PyObjectRef,
684684
}
685685

686686
#[derive(FromArgs)]
687687
struct IncrementalDecodeArgs {
688688
#[pyarg(any)]
689689
input: ArgBytesLike,
690690
// Any object is accepted by truthiness.
691-
#[pyarg(any, name = "final", default = false)]
692-
final_input: PyObjectRef,
691+
#[pyarg(any, default = false)]
692+
r#final: PyObjectRef,
693693
}
694694

695695
/// The `bool(accept={int})` conversion the `final` arguments share, which
@@ -753,7 +753,7 @@ mod _multibytecodec {
753753
args: IncrementalEncodeArgs,
754754
vm: &VirtualMachine,
755755
) -> PyResult<PyObjectRef> {
756-
let final_input = final_arg(args.final_input, vm)?;
756+
let final_input = final_arg(args.r#final, vm)?;
757757
// Driven on a detached copy: an error handler can re-enter this object.
758758
let mut local = zelf.inner.lock().clone();
759759
let result = zelf
@@ -884,7 +884,7 @@ mod _multibytecodec {
884884
args: IncrementalDecodeArgs,
885885
vm: &VirtualMachine,
886886
) -> PyResult<PyStrRef> {
887-
let final_input = final_arg(args.final_input, vm)?;
887+
let final_input = final_arg(args.r#final, vm)?;
888888
// Driven on a detached copy: an error handler can re-enter this object.
889889
let mut local = zelf.inner.lock().clone();
890890
let original_pending = core::mem::take(&mut local.pending);

‎crates/stdlib/src/csv.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ mod _csv {
137137
Some(vm.ctx.new_str(zelf.escapechar?))
138138
}
139139

140-
#[pygetset(name = "strict")]
141-
fn get_strict(zelf: &Py<Self>) -> bool {
140+
#[pygetset]
141+
fn strict(zelf: &Py<Self>) -> bool {
142142
zelf.strict
143143
}
144144
}
@@ -1062,8 +1062,8 @@ mod _csv {
10621062

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

0 commit comments

Comments
 (0)