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
5 changes: 3 additions & 2 deletions crates/stdlib/src/contextvars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ mod _contextvars {
use crate::vm::{
AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, atomic_func,
builtins::{PyGenericAlias, PyList, PyStrRef, PyType, PyTypeRef},
class::PyClassDef,
class::StaticType,
common::{
hash::PyHash,
lock::{LazyLock, PyMutex},
wtf8::Wtf8Buf,
},
function::{ArgCallable, Callee, FuncArgs, OptionalArg},
function::{ArgCallable, FuncArgs, OptionalArg},
protocol::{PyMappingMethods, PySequenceMethods},
types::{AsMapping, AsSequence, Constructor, Hashable, Iterable, Representable},
};
Expand Down Expand Up @@ -484,7 +485,7 @@ mod _contextvars {
type Args = ContextVarOptions;

fn slot_new(cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
let args: Self::Args = args.bind_for(vm, Callee::of::<Self>(vm))?;
let args: Self::Args = args.bind_for(vm, Self::NAME)?;
let var = Self {
name: args.name.to_string(),
default: args.default.into_option(),
Expand Down
11 changes: 5 additions & 6 deletions crates/stdlib/src/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,12 +731,11 @@ mod _csv {
};

if let Some(last_arg) = args.kwargs.pop() {
return Err(
rustpython_vm::function::ArgumentError::InvalidKeywordArgument(format!(
"'{}' is an invalid keyword argument for this function",
last_arg.0
)),
);
// The dialect is parsed by a parser of its own, which has no
// name to give the message.
return Err(ArgumentError::Exception(
vm.new_unexpected_keyword_type_error(None, &last_arg.0.to_string()),
));
}

Ok(res)
Expand Down
6 changes: 3 additions & 3 deletions crates/vm/src/builtins/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use super::{PyInt, PyStrRef, PyType, PyTypeRef, PyUtf8StrRef};
use crate::common::format::FormatSpec;
use crate::{
AsObject, Context, Py, PyObject, PyObjectRef, PyResult, TryFromBorrowedObject, VirtualMachine,
class::PyClassImpl,
class::{PyClassDef, PyClassImpl},
convert::{IntoPyException, ToPyObject, ToPyResult},
function::{Callee, FuncArgs, OptionalArg},
function::{FuncArgs, OptionalArg},
protocol::PyNumberMethods,
types::{AsNumber, Constructor, Representable},
};
Expand Down Expand Up @@ -87,7 +87,7 @@ impl Constructor for PyBool {
type Args = OptionalArg<PyObjectRef>;

fn slot_new(zelf: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
let x: Self::Args = args.bind_for(vm, Callee::of::<Self>(vm))?;
let x: Self::Args = args.bind_for(vm, Self::NAME)?;
if !zelf.fast_isinstance(vm.ctx.types.type_type) {
return Err(vm.new_type_error(format!(
"requires a 'type' object but received a '{}'",
Expand Down
8 changes: 3 additions & 5 deletions crates/vm/src/builtins/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ use crate::{
ByteInnerSplitOptions, ByteInnerSub, ByteInnerTranslateOptions, DecodeArgs, PyBytesInner,
bytes_decode,
},
class::PyClassImpl,
class::{PyClassDef, PyClassImpl},
common::{hash::PyHash, lock::PyMutex},
convert::{ToPyObject, ToPyResult},
function::{
ArgBytesLike, ArgIndex, Callee, FuncArgs, OptionalArg, OptionalOption, PyComparisonValue,
},
function::{ArgBytesLike, ArgIndex, FuncArgs, OptionalArg, OptionalOption, PyComparisonValue},
protocol::{
BufferDescriptor, BufferFlags, BufferMethods, PyBuffer, PyIterReturn, PyMappingMethods,
PyNumberMethods, PySequenceMethods,
Expand Down Expand Up @@ -97,7 +95,7 @@ impl Constructor for PyBytes {
type Args = Vec<u8>;

fn slot_new(cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
let options: ByteInnerNewOptions = args.bind_for(vm, Callee::of::<Self>(vm))?;
let options: ByteInnerNewOptions = args.bind_for(vm, Self::NAME)?;

// Optimizations for exact bytes type
if cls.is(vm.ctx.types.bytes_type) {
Expand Down
6 changes: 3 additions & 3 deletions crates/vm/src/builtins/classmethod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::{PyBoundMethod, PyGenericAlias, PyStr, PyType, PyTypeRef};
use crate::{
AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
class::PyClassImpl,
class::{PyClassDef, PyClassImpl},
common::lock::PyMutex,
function::{Callee, FuncArgs, PySetterValue},
function::{FuncArgs, PySetterValue},
types::{Constructor, GetDescriptor, Initializer, Representable},
};

Expand Down Expand Up @@ -70,7 +70,7 @@ impl Constructor for PyClassMethod {
// copying its attributes to `__init__` so that subclasses overriding
// `__init__` without calling `super().__init__()` see `__func__` as
// `None`, matching CPython.
let _: Self::Args = args.bind_for(vm, Callee::of::<Self>(vm))?;
let _: Self::Args = args.bind_for(vm, Self::NAME)?;
let classmethod = Self {
callable: PyMutex::new(vm.ctx.none()),
};
Expand Down
6 changes: 3 additions & 3 deletions crates/vm/src/builtins/complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use super::{PyStr, PyType, PyTypeRef, float};
use crate::{
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
builtins::PyUtf8StrRef,
class::PyClassImpl,
class::{PyClassDef, PyClassImpl},
common::{format::FormatSpec, wtf8::Wtf8Buf},
convert::{IntoPyException, ToPyObject, ToPyResult},
function::{Callee, FuncArgs, OptionalArg, PyComparisonValue},
function::{FuncArgs, OptionalArg, PyComparisonValue},
protocol::PyNumberMethods,
stdlib::_warnings,
types::{AsNumber, Callable, Comparable, Constructor, Hashable, PyComparisonOp, Representable},
Expand Down Expand Up @@ -395,7 +395,7 @@ impl Constructor for PyComplex {
return Ok(func_args.args[0].clone());
}

let args: Self::Args = func_args.bind_for(vm, Callee::of::<Self>(vm))?;
let args: Self::Args = func_args.bind_for(vm, Self::NAME)?;
let payload = Self::py_new(&cls, args, vm)?;
payload.into_ref_with_type(vm, cls).map(Into::into)
}
Expand Down
7 changes: 3 additions & 4 deletions crates/vm/src/builtins/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ use super::{
use crate::{
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult,
TryFromBorrowedObject, TryFromObject, VirtualMachine,
class::PyClassImpl,
class::{PyClassDef, PyClassImpl},
common::{float_ops, format::FormatSpec, hash, wtf8::Wtf8Buf},
convert::{IntoPyException, ToPyObject, ToPyResult},
function::{
ArgBytesLike, Callee, FuncArgs, OptionalArg, OptionalOption, PyArithmeticValue,
PyComparisonValue,
ArgBytesLike, FuncArgs, OptionalArg, OptionalOption, PyArithmeticValue, PyComparisonValue,
},
protocol::PyNumberMethods,
types::{AsNumber, Callable, Comparable, Constructor, Hashable, PyComparisonOp, Representable},
Expand Down Expand Up @@ -179,7 +178,7 @@ impl Constructor for PyFloat {
fn slot_new(cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
// Bind before the fast path so FromArgs::arity decides how many arguments
// are acceptable, rather than a count repeated here.
let arg: Self::Args = args.bind_for(vm, Callee::of::<Self>(vm))?;
let arg: Self::Args = args.bind_for(vm, Self::NAME)?;

// Optimization: return exact float as-is
if cls.is(vm.ctx.types.float_type)
Expand Down
11 changes: 4 additions & 7 deletions crates/vm/src/builtins/frame_locals_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::{PyDict, PyDictRef, PyType};
use crate::{
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
atomic_func,
class::PyClassImpl,
class::{PyClassDef, PyClassImpl},
frame::FrameObjectRef,
function::{FuncArgs, OptionalArg, PyArithmeticValue, PyComparisonValue},
object::{Traverse, TraverseFn},
Expand Down Expand Up @@ -71,16 +71,13 @@ impl Constructor for FrameLocalsProxy {
type Args = FuncArgs;

fn py_new(_cls: &Py<PyType>, args: Self::Args, vm: &VirtualMachine) -> PyResult<Self> {
if args.args.len() != 1 {
return Err(vm.new_arity_type_error(Self::NAME, 1..=1, args.args.len()));
}
if !args.kwargs.is_empty() {
return Err(vm.new_type_error("FrameLocalsProxy() takes no keyword arguments"));
}
let mut args = args.args;
if args.len() != 1 {
return Err(vm.new_type_error(format!(
"FrameLocalsProxy expected 1 argument, got {}",
args.len()
)));
}
let frame: FrameObjectRef = args
.pop()
.unwrap()
Expand Down
4 changes: 2 additions & 2 deletions crates/vm/src/builtins/genericalias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject,
VirtualMachine, atomic_func,
builtins::{PyList, PyStr, PyTuple, PyTupleRef, PyType},
class::PyClassImpl,
class::{PyClassDef, PyClassImpl},
common::hash,
convert::ToPyObject,
function::{FuncArgs, PyComparisonValue},
Expand Down Expand Up @@ -62,7 +62,7 @@ impl Constructor for PyGenericAlias {
if !args.kwargs.is_empty() {
return Err(vm.new_type_error("GenericAlias() takes no keyword arguments"));
}
let (origin, arguments): (PyObjectRef, PyObjectRef) = args.bind(vm)?;
let (origin, arguments): (PyObjectRef, PyObjectRef) = args.bind_for(vm, Self::NAME)?;
let args = if let Ok(tuple) = arguments.try_to_ref::<PyTuple>(vm) {
tuple.to_owned()
} else {
Expand Down
8 changes: 4 additions & 4 deletions crates/vm/src/builtins/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
TryFromBorrowedObject, VirtualMachine,
builtins::PyUtf8StrRef,
byte::bytes_from_object,
class::PyClassImpl,
class::{PyClassDef, PyClassImpl},
common::{
format::FormatSpec,
hash,
Expand All @@ -13,8 +13,8 @@ use crate::{
},
convert::{IntoPyException, ToPyObject, ToPyResult},
function::{
ArgByteOrder, ArgIntoBool, Callee, FuncArgs, OptionalArg, OptionalOption,
PyArithmeticValue, PyComparisonValue,
ArgByteOrder, ArgIntoBool, FuncArgs, OptionalArg, OptionalOption, PyArithmeticValue,
PyComparisonValue,
},
protocol::{PyNumberMethods, handle_bytes_to_int_err, numeric_literal_from_str},
types::{AsNumber, Comparable, Constructor, Hashable, PyComparisonOp, Representable},
Expand Down Expand Up @@ -259,7 +259,7 @@ impl Constructor for PyInt {
return Ok(args.args[0].clone());
}

let options: IntOptions = args.bind_for(vm, Callee::of::<Self>(vm))?;
let options: IntOptions = args.bind_for(vm, Self::NAME)?;
let value = if let OptionalArg::Present(val) = options.val_options {
if let OptionalArg::Present(base) = options.base {
let base = base
Expand Down
10 changes: 5 additions & 5 deletions crates/vm/src/builtins/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use crate::common::lock::LazyLock;
use crate::{
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject,
VirtualMachine, atomic_func,
class::PyClassImpl,
class::{PyClassDef, PyClassImpl},
common::hash::PyHash,
function::{ArgIndex, Callee, FuncArgs, OptionalArg, PyComparisonValue},
function::{ArgIndex, FuncArgs, OptionalArg, PyComparisonValue},
protocol::{PyIterReturn, PyMappingMethods, PyNumberMethods, PySequenceMethods},
types::{
AsMapping, AsNumber, AsSequence, Comparable, Hashable, IterNext, Iterable, PyComparisonOp,
Expand Down Expand Up @@ -352,12 +352,12 @@ impl PyRange {
#[pyslot]
fn slot_new(cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
let range = if args.args.is_empty() {
return Err(Callee::of::<Self>(vm).arity_error(1..=3, 0, vm));
return Err(vm.new_arity_type_error(Self::NAME, 1..=3, 0));
} else if args.args.len() == 1 {
let stop = args.bind_for(vm, Callee::of::<Self>(vm))?;
let stop = args.bind_for(vm, Self::NAME)?;
Self::new(cls, stop, vm)
} else {
let (start, stop, step) = args.bind_for(vm, Callee::of::<Self>(vm))?;
let (start, stop, step) = args.bind_for(vm, Self::NAME)?;
Self::new_from(cls, start, stop, step, vm)
}?;

Expand Down
13 changes: 4 additions & 9 deletions crates/vm/src/builtins/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::{
use crate::{
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject,
atomic_func,
class::PyClassImpl,
class::{PyClassDef, PyClassImpl},
common::{
ascii,
hash::PyHash,
Expand All @@ -18,9 +18,7 @@ use crate::{
},
convert::ToPyResult,
dict_inner::{self, DictSize},
function::{
ArgIterable, Callee, FuncArgs, OptionalArg, PosArgs, PyArithmeticValue, PyComparisonValue,
},
function::{ArgIterable, FuncArgs, OptionalArg, PosArgs, PyArithmeticValue, PyComparisonValue},
protocol::{PyIterReturn, PyNumberMethods, PySequenceMethods},
recursion::ReprGuard,
types::AsNumber,
Expand Down Expand Up @@ -1079,7 +1077,7 @@ impl Constructor for PyFrozenSet {

// Optimizations for exact frozenset type
let iterable_opt = if is_exact_frozenset || is_frozenset_init {
let iterable: OptionalArg<PyObjectRef> = args.bind_for(vm, Callee::of::<Self>(vm))?;
let iterable: OptionalArg<PyObjectRef> = args.bind_for(vm, Self::NAME)?;

// Return exact frozenset as-is
if is_exact_frozenset
Expand All @@ -1095,10 +1093,7 @@ impl Constructor for PyFrozenSet {
[] => OptionalArg::Missing,
[iterable] => OptionalArg::Present(iterable.clone()),
slice => {
return Err(vm.new_type_error(format!(
"frozenset expected at most 1 argument, got {}",
slice.len()
)));
return Err(vm.new_arity_type_error(Self::NAME, 0..=1, slice.len()));
}
}
};
Expand Down
8 changes: 4 additions & 4 deletions crates/vm/src/builtins/singletons.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::{PyStrRef, PyType, PyTypeRef};
use crate::{
Context, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,
class::PyClassImpl,
class::{PyClassDef, PyClassImpl},
common::hash::PyHash,
convert::ToPyObject,
function::{Callee, FuncArgs, PyComparisonValue},
function::{FuncArgs, PyComparisonValue},
protocol::PyNumberMethods,
types::{AsNumber, Comparable, Constructor, Hashable, PyComparisonOp, Representable},
};
Expand Down Expand Up @@ -41,7 +41,7 @@ impl Constructor for PyNone {
type Args = ();

fn slot_new(_cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
let _: () = args.bind_for(vm, Callee::of::<Self>(vm))?;
let _: () = args.bind_for(vm, Self::NAME)?;
Ok(vm.ctx.none.clone().into())
}

Expand Down Expand Up @@ -110,7 +110,7 @@ impl Constructor for PyNotImplemented {
type Args = ();

fn slot_new(_cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
let _: () = args.bind_for(vm, Callee::of::<Self>(vm))?;
let _: () = args.bind_for(vm, Self::NAME)?;
Ok(vm.ctx.not_implemented.clone().into())
}

Expand Down
12 changes: 6 additions & 6 deletions crates/vm/src/builtins/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use rustpython_common::wtf8::{Wtf8Buf, wtf8_concat};
use super::{PyGenericAlias, PyStrRef, PyTupleRef, PyType, PyTypeRef};
use crate::{
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
class::PyClassImpl,
class::{PyClassDef, PyClassImpl},
common::hash::{PyHash, PyUHash},
convert::ToPyObject,
function::{ArgIndex, Callee, FuncArgs, OptionalArg, PyComparisonValue},
function::{ArgIndex, FuncArgs, OptionalArg, PyComparisonValue},
sliceable::SaturatedSlice,
types::{Comparable, Constructor, Hashable, PyComparisonOp, Representable},
};
Expand Down Expand Up @@ -128,10 +128,10 @@ impl PySlice {
fn slot_new(cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
let slice: Self = match args.args.len() {
0 => {
return Err(Callee::of::<Self>(vm).arity_error(1..=3, 0, vm));
return Err(vm.new_arity_type_error(Self::NAME, 1..=3, 0));
}
1 => {
let stop = args.bind_for(vm, Callee::of::<Self>(vm))?;
let stop = args.bind_for(vm, Self::NAME)?;
Self {
start: None,
stop,
Expand All @@ -140,7 +140,7 @@ impl PySlice {
}
_ => {
let (start, stop, step): (PyObjectRef, PyObjectRef, OptionalArg<PyObjectRef>) =
args.bind_for(vm, Callee::of::<Self>(vm))?;
args.bind_for(vm, Self::NAME)?;
Self {
start: Some(start),
stop,
Expand Down Expand Up @@ -388,7 +388,7 @@ impl Constructor for PyEllipsis {
type Args = ();

fn slot_new(_cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
let _: () = args.bind_for(vm, Callee::of::<Self>(vm))?;
let _: () = args.bind_for(vm, Self::NAME)?;
Ok(vm.ctx.ellipsis.clone().into())
}

Expand Down
6 changes: 3 additions & 3 deletions crates/vm/src/builtins/staticmethod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::{PyGenericAlias, PyStr, PyType, PyTypeRef};
use crate::{
AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
class::PyClassImpl,
class::{PyClassDef, PyClassImpl},
common::lock::PyMutex,
function::{Callee, FuncArgs, PySetterValue},
function::{FuncArgs, PySetterValue},
types::{Callable, Constructor, GetDescriptor, Initializer, Representable},
};

Expand Down Expand Up @@ -48,7 +48,7 @@ impl Constructor for PyStaticMethod {
// copying its attributes to `__init__` so that subclasses overriding
// `__init__` without calling `super().__init__()` see `__func__` as
// `None`, matching CPython.
let _: Self::Args = args.bind_for(vm, Callee::of::<Self>(vm))?;
let _: Self::Args = args.bind_for(vm, Self::NAME)?;
let result = Self {
callable: PyMutex::new(vm.ctx.none()),
}
Expand Down
Loading
Loading