Skip to content
Merged
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"TESTFN",
"TZPATH",
"unraisable",
"ustr",
"wasi",
"weaked",
// unix
Expand Down
2 changes: 0 additions & 2 deletions Lib/test/test_pydoc/test_pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1604,12 +1604,10 @@ def test_bound_builtin_method_noargs(self):
self.assertEqual(self._get_summary_line(''.lower),
"lower() method of builtins.str instance")

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_unbound_builtin_method_o(self):
self.assertEqual(self._get_summary_line(set.add),
"add(self, object, /) unbound builtins.set method")

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_bound_builtin_method_o(self):
self.assertEqual(self._get_summary_line(set().add),
"add(object, /) method of builtins.set instance")
Expand Down
8 changes: 5 additions & 3 deletions crates/derive-impl/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use itertools::Itertools;
use proc_macro2::{Span, TokenStream};
use quote::{ToTokens, quote};
use std::collections::{HashMap, HashSet};
use syn::{Attribute, FnArg, Ident, Result, Signature, UseTree, spanned::Spanned};
use syn::{Attribute, FnArg, Ident, Result, Signature, UseTree, ext::IdentExt, spanned::Spanned};
use syn_ext::{
ext::{AttributeExt as SynAttributeExt, *},
types::*,
Expand Down Expand Up @@ -868,11 +868,13 @@ fn func_sig(sig: &Signature, mut implicit_self: Option<&str>) -> Option<String>
let syn::Pat::Ident(pat) = arg.pat.as_ref() else {
return None;
};
let ident = pat.ident.to_string();
let ident = pat.ident.unraw().to_string();
if ident == "vm" {
unreachable!("type &VirtualMachine(`{ty}`) must be filtered already");
}
params.push(ident);
// A leading `_` only marks the argument unused in Rust. A parameter whose
// Python name really starts with `_` has to be a FromArgs field instead.
params.push(ident.strip_prefix('_').unwrap_or(&ident).to_owned());
}
Some(params.join(", "))
}
Expand Down
44 changes: 22 additions & 22 deletions crates/stdlib/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,8 @@ pub mod array {
}

#[pymethod]
fn append(zelf: &Py<Self>, x: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
zelf.try_resizable(vm)?.push(x, vm)
fn append(zelf: &Py<Self>, v: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
zelf.try_resizable(vm)?.push(v, vm)
}

#[pymethod]
Expand All @@ -814,24 +814,24 @@ pub mod array {
}

#[pymethod]
fn count(&self, x: PyObjectRef, vm: &VirtualMachine) -> usize {
self.read().count(x, vm)
fn count(&self, v: PyObjectRef, vm: &VirtualMachine) -> usize {
self.read().count(v, vm)
}

#[pymethod]
fn remove(zelf: &Py<Self>, x: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
zelf.try_resizable(vm)?.remove(x, vm)
fn remove(zelf: &Py<Self>, v: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
zelf.try_resizable(vm)?.remove(v, vm)
}

#[pymethod]
fn extend(zelf: &Py<Self>, obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
fn extend(zelf: &Py<Self>, bb: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
let mut w = zelf.try_resizable(vm)?;
if zelf.is(&obj) {
if zelf.is(&bb) {
w.imul(2, vm)
} else if let Some(array) = obj.downcast_ref::<Self>() {
} else if let Some(array) = bb.downcast_ref::<Self>() {
w.iadd(&array.read(), vm)
} else {
let iter = ArgIterable::try_from_object(vm, obj)?;
let iter = ArgIterable::try_from_object(vm, bb)?;
// zelf.extend_from_iterable(iter, vm)
for obj in iter.iter(vm)? {
w.push(obj?, vm)?;
Expand Down Expand Up @@ -883,11 +883,11 @@ pub mod array {
}

#[pymethod]
fn fromunicode(zelf: &Py<Self>, obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
let wtf8: &Wtf8 = obj.try_to_value(vm).map_err(|_| {
fn fromunicode(zelf: &Py<Self>, ustr: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
let wtf8: &Wtf8 = ustr.try_to_value(vm).map_err(|_| {
vm.new_type_error(format!(
"fromunicode() argument must be str, not {}",
obj.class().name()
ustr.class().name()
))
})?;
if !matches!(zelf.read().typecode(), 'u' | 'w') {
Expand Down Expand Up @@ -924,15 +924,15 @@ pub mod array {
}

#[pymethod]
fn frombytes(&self, b: ArgBytesLike, vm: &VirtualMachine) -> PyResult<()> {
fn frombytes(&self, buffer: ArgBytesLike, vm: &VirtualMachine) -> PyResult<()> {
// The source is read as bytes, so items of any other width would
// be reinterpreted rather than appended.
if b.itemsize() != 1 {
if buffer.itemsize() != 1 {
return Err(vm.new_type_error("a bytes-like object is required"));
}
let b = b.borrow_buf();
let buffer = buffer.borrow_buf();
let itemsize = self.read().itemsize();
self._from_bytes(&b, itemsize, vm)
self._from_bytes(&buffer, itemsize, vm)
}

#[pymethod]
Expand Down Expand Up @@ -977,9 +977,9 @@ pub mod array {
}

#[pymethod]
fn insert(zelf: &Py<Self>, i: isize, x: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
fn insert(zelf: &Py<Self>, i: isize, v: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
let mut w = zelf.try_resizable(vm)?;
w.insert(i, x, vm)
w.insert(i, v, vm)
}

#[pymethod]
Expand Down Expand Up @@ -1049,7 +1049,7 @@ pub mod array {
}

#[pymethod]
fn __deepcopy__(&self, _memo: PyObjectRef) -> Self {
fn __deepcopy__(&self, _unused: PyObjectRef) -> Self {
self.__copy__()
}

Expand Down Expand Up @@ -1198,10 +1198,10 @@ pub mod array {
#[pymethod]
fn __reduce_ex__(
zelf: &Py<Self>,
proto: usize,
value: usize,
vm: &VirtualMachine,
) -> PyResult<(PyObjectRef, PyTupleRef, Option<PyDictRef>)> {
if proto < 3 {
if value < 3 {
return Self::__reduce__(zelf, vm);
}
let array = zelf.read();
Expand Down
19 changes: 10 additions & 9 deletions crates/stdlib/src/binascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,21 @@ mod decl {

#[pyfunction(name = "a2b_hex")]
#[pyfunction]
fn unhexlify(data: ArgAsciiBuffer, vm: &VirtualMachine) -> PyResult<Vec<u8>> {
data.with_ref(binascii::unhexlify)
fn unhexlify(hexstr: ArgAsciiBuffer, vm: &VirtualMachine) -> PyResult<Vec<u8>> {
hexstr
.with_ref(binascii::unhexlify)
.map_err(|e| new_binascii_error(e, vm))
}

#[pyfunction]
pub(crate) fn crc32(data: ArgBytesLike, init: OptionalArg<PyIntRef>) -> u32 {
let init = init.map_or(0, |i| i.as_u32_mask());
data.with_ref(|bytes| binascii::crc32(bytes, init))
pub(crate) fn crc32(data: ArgBytesLike, crc: OptionalArg<PyIntRef>) -> u32 {
let crc = crc.map_or(0, |i| i.as_u32_mask());
data.with_ref(|bytes| binascii::crc32(bytes, crc))
}

#[pyfunction]
pub(crate) fn crc_hqx(data: ArgBytesLike, init: PyIntRef) -> u32 {
data.with_ref(|bytes| binascii::crc_hqx(bytes, init.as_u32_mask()))
pub(crate) fn crc_hqx(data: ArgBytesLike, crc: PyIntRef) -> u32 {
data.with_ref(|bytes| binascii::crc_hqx(bytes, crc.as_u32_mask()))
}

#[derive(FromArgs)]
Expand Down Expand Up @@ -136,8 +137,8 @@ mod decl {
}

#[pyfunction]
fn a2b_uu(s: ArgAsciiBuffer, vm: &VirtualMachine) -> PyResult<Vec<u8>> {
s.with_ref(binascii::a2b_uu)
fn a2b_uu(data: ArgAsciiBuffer, vm: &VirtualMachine) -> PyResult<Vec<u8>> {
data.with_ref(binascii::a2b_uu)
.map_err(|e| new_binascii_error(e, vm))
}

Expand Down
4 changes: 2 additions & 2 deletions crates/stdlib/src/cmath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ mod cmath {
}

#[pyfunction]
fn polar(x: ArgIntoComplex, vm: &VirtualMachine) -> PyResult<(f64, f64)> {
pymath::cmath::polar(x.into_complex()).map_err(|err| pymath_exception(err, vm))
fn polar(z: ArgIntoComplex, vm: &VirtualMachine) -> PyResult<(f64, f64)> {
pymath::cmath::polar(z.into_complex()).map_err(|err| pymath_exception(err, vm))
}

#[pyfunction]
Expand Down
10 changes: 5 additions & 5 deletions crates/stdlib/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,8 +762,8 @@ mod math {
// Integer functions:

#[pyfunction]
fn isqrt(x: ArgIndex, vm: &VirtualMachine) -> PyResult<BigInt> {
let value = x.into_int_ref();
fn isqrt(n: ArgIndex, vm: &VirtualMachine) -> PyResult<BigInt> {
let value = n.into_int_ref();
pymath::math::integer::isqrt(value.as_bigint())
.map_err(|_| vm.new_value_error("isqrt() argument must be nonnegative"))
}
Expand Down Expand Up @@ -791,12 +791,12 @@ mod math {
}

#[pyfunction]
fn factorial(x: PyIntRef, vm: &VirtualMachine) -> PyResult<BigInt> {
fn factorial(n: PyIntRef, vm: &VirtualMachine) -> PyResult<BigInt> {
// Check for negative before overflow - negative values are always invalid
if x.as_bigint().is_negative() {
if n.as_bigint().is_negative() {
return Err(vm.new_value_error("factorial() not defined for negative values"));
}
let n: i64 = x.try_to_primitive(vm).map_err(|_| {
let n: i64 = n.try_to_primitive(vm).map_err(|_| {
vm.new_overflow_error("factorial() argument should not exceed 9223372036854775807")
})?;
pymath::math::integer::factorial(n)
Expand Down
16 changes: 8 additions & 8 deletions crates/stdlib/src/pystruct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ pub(crate) mod _struct {

#[pyfunction]
fn unpack(
fmt: IntoStructFormatBytes,
format: IntoStructFormatBytes,
buffer: ArgBytesLike,
vm: &VirtualMachine,
) -> PyResult<PyTupleRef> {
let format_spec = fmt.format_spec(vm)?;
let format_spec = format.format_spec(vm)?;
buffer.with_ref(|buf| format_spec.unpack(buf, vm))
}

Expand Down Expand Up @@ -239,17 +239,17 @@ pub(crate) mod _struct {

#[pyfunction]
fn iter_unpack(
fmt: IntoStructFormatBytes,
format: IntoStructFormatBytes,
buffer: ArgBytesLike,
vm: &VirtualMachine,
) -> PyResult<UnpackIterator> {
let format_spec = fmt.format_spec(vm)?;
let format_spec = format.format_spec(vm)?;
UnpackIterator::with_buffer(vm, format_spec, buffer)
}

#[pyfunction]
fn calcsize(fmt: IntoStructFormatBytes, vm: &VirtualMachine) -> PyResult<usize> {
Ok(fmt.format_spec(vm)?.size)
fn calcsize(format: IntoStructFormatBytes, vm: &VirtualMachine) -> PyResult<usize> {
Ok(format.format_spec(vm)?.size)
}

/// What a `Struct` is once a format has been read into it. Held apart
Expand Down Expand Up @@ -342,9 +342,9 @@ pub(crate) mod _struct {
}

#[pymethod]
fn unpack(&self, data: ArgBytesLike, vm: &VirtualMachine) -> PyResult<PyTupleRef> {
fn unpack(&self, buffer: ArgBytesLike, vm: &VirtualMachine) -> PyResult<PyTupleRef> {
let inner = self.ready(vm)?;
data.with_ref(|buf| inner.spec.unpack(buf, vm))
buffer.with_ref(|buf| inner.spec.unpack(buf, vm))
}

#[pymethod]
Expand Down
Loading
Loading