diff --git a/derive/src/pyclass.rs b/derive/src/pyclass.rs index 9a25f9f9f..921afd0b7 100644 --- a/derive/src/pyclass.rs +++ b/derive/src/pyclass.rs @@ -207,15 +207,25 @@ impl Class { )?; attr_idxs.push(i); } else if name == "pyslot" { - let pyslot_err = "#[pyslot] must be of the form #[pyslot(slotname)]"; + let pyslot_err = "#[pyslot] must be of the form #[pyslot] or #[pyslot(slotname)]"; let nesteds = meta_to_vec(meta).map_err(|meta| err_span!(meta, "{}", pyslot_err))?; - if nesteds.len() != 1 { + if nesteds.len() > 1 { return Err(Diagnostic::spanned_error("e!(#(#nesteds)*), pyslot_err)); } - let slot_ident = match nesteds.into_iter().next().unwrap() { - NestedMeta::Meta(Meta::Word(ident)) => ident, - bad => bail_span!(bad, "{}", pyslot_err), + let slot_ident = if nesteds.is_empty() { + let ident_str = sig.ident.to_string(); + if ident_str.starts_with("tp_") { + let slot_name = &ident_str[3..]; + proc_macro2::Ident::new(slot_name, sig.ident.span()) + } else { + sig.ident.clone() + } + } else { + match nesteds.into_iter().next().unwrap() { + NestedMeta::Meta(Meta::Word(ident)) => ident, + bad => bail_span!(bad, "{}", pyslot_err), + } }; self.add_item( ClassItem::Slot { diff --git a/vm/src/exceptions.rs b/vm/src/exceptions.rs index 4b91b2bad..87654fb54 100644 --- a/vm/src/exceptions.rs +++ b/vm/src/exceptions.rs @@ -55,7 +55,7 @@ impl PyBaseException { } } - #[pyslot(new)] + #[pyslot] fn tp_new(cls: PyClassRef, args: PyFuncArgs, vm: &VirtualMachine) -> PyResult> { PyBaseException::new(args.args, vm).into_ref_with_type(vm, cls) } diff --git a/vm/src/obj/objbytearray.rs b/vm/src/obj/objbytearray.rs index b713eed01..072d1eed9 100644 --- a/vm/src/obj/objbytearray.rs +++ b/vm/src/obj/objbytearray.rs @@ -89,7 +89,7 @@ pub(crate) fn init(context: &PyContext) { #[pyimpl] impl PyByteArray { - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, options: ByteInnerNewOptions, diff --git a/vm/src/obj/objbytes.rs b/vm/src/obj/objbytes.rs index 9063d4b32..c8b5b5c3b 100644 --- a/vm/src/obj/objbytes.rs +++ b/vm/src/obj/objbytes.rs @@ -91,7 +91,7 @@ pub(crate) fn init(context: &PyContext) { #[pyimpl] impl PyBytes { - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, options: ByteInnerNewOptions, diff --git a/vm/src/obj/objclassmethod.rs b/vm/src/obj/objclassmethod.rs index 2065da1a6..c3368da27 100644 --- a/vm/src/obj/objclassmethod.rs +++ b/vm/src/obj/objclassmethod.rs @@ -55,7 +55,7 @@ impl PyBuiltinDescriptor for PyClassMethod { #[pyimpl] impl PyClassMethod { - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, callable: PyObjectRef, diff --git a/vm/src/obj/objcomplex.rs b/vm/src/obj/objcomplex.rs index 80534a6cb..da9e4d57b 100644 --- a/vm/src/obj/objcomplex.rs +++ b/vm/src/obj/objcomplex.rs @@ -213,7 +213,7 @@ impl PyComplex { !Complex64::is_zero(&self.value) } - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, real: OptionalArg, diff --git a/vm/src/obj/objenumerate.rs b/vm/src/obj/objenumerate.rs index 29617b7df..0eddb0c61 100644 --- a/vm/src/obj/objenumerate.rs +++ b/vm/src/obj/objenumerate.rs @@ -27,7 +27,7 @@ impl PyValue for PyEnumerate { #[pyimpl] impl PyEnumerate { - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, iterable: PyObjectRef, diff --git a/vm/src/obj/objfilter.rs b/vm/src/obj/objfilter.rs index 9a64235e4..f633d91eb 100644 --- a/vm/src/obj/objfilter.rs +++ b/vm/src/obj/objfilter.rs @@ -25,7 +25,7 @@ impl PyValue for PyFilter { #[pyimpl] impl PyFilter { - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, function: PyObjectRef, diff --git a/vm/src/obj/objfloat.rs b/vm/src/obj/objfloat.rs index b0ccacdc6..1920425b1 100644 --- a/vm/src/obj/objfloat.rs +++ b/vm/src/obj/objfloat.rs @@ -176,7 +176,7 @@ fn int_eq(value: f64, other: &BigInt) -> bool { #[pyimpl] #[allow(clippy::trivially_copy_pass_by_ref)] impl PyFloat { - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, arg: OptionalArg, diff --git a/vm/src/obj/objframe.rs b/vm/src/obj/objframe.rs index e4201bd0d..46eaf5299 100644 --- a/vm/src/obj/objframe.rs +++ b/vm/src/obj/objframe.rs @@ -14,7 +14,7 @@ pub fn init(context: &PyContext) { #[pyimpl] impl FrameRef { - #[pyslot(new)] + #[pyslot] fn tp_new(_cls: FrameRef, vm: &VirtualMachine) -> PyResult { Err(vm.new_type_error("Cannot directly create frame object".to_string())) } diff --git a/vm/src/obj/objint.rs b/vm/src/obj/objint.rs index 112bc6975..741a983c5 100644 --- a/vm/src/obj/objint.rs +++ b/vm/src/obj/objint.rs @@ -213,7 +213,7 @@ fn inner_truediv(i1: &BigInt, i2: &BigInt, vm: &VirtualMachine) -> PyResult { #[pyimpl] impl PyInt { - #[pyslot(new)] + #[pyslot] fn tp_new(cls: PyClassRef, options: IntOptions, vm: &VirtualMachine) -> PyResult { PyInt::new(options.get_int_value(vm)?).into_ref_with_type(vm, cls) } diff --git a/vm/src/obj/objlist.rs b/vm/src/obj/objlist.rs index 85672ac24..3013c0652 100644 --- a/vm/src/obj/objlist.rs +++ b/vm/src/obj/objlist.rs @@ -762,8 +762,8 @@ impl PyList { Ok(()) } - #[pyslot(new)] - fn list_new( + #[pyslot] + fn tp_new( cls: PyClassRef, iterable: OptionalArg, vm: &VirtualMachine, diff --git a/vm/src/obj/objmap.rs b/vm/src/obj/objmap.rs index 1fd272afb..bfc0db12a 100644 --- a/vm/src/obj/objmap.rs +++ b/vm/src/obj/objmap.rs @@ -24,7 +24,7 @@ impl PyValue for PyMap { #[pyimpl] impl PyMap { - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, function: PyObjectRef, diff --git a/vm/src/obj/objmappingproxy.rs b/vm/src/obj/objmappingproxy.rs index 3ab31696a..450a37cea 100644 --- a/vm/src/obj/objmappingproxy.rs +++ b/vm/src/obj/objmappingproxy.rs @@ -36,7 +36,7 @@ impl PyMappingProxy { } } - #[pyslot(new)] + #[pyslot] fn tp_new(cls: PyClassRef, mapping: PyObjectRef, vm: &VirtualMachine) -> PyResult> { PyMappingProxy { mapping: MappingProxyInner::Dict(mapping), diff --git a/vm/src/obj/objmemory.rs b/vm/src/obj/objmemory.rs index 7b84385f4..31cd21ebd 100644 --- a/vm/src/obj/objmemory.rs +++ b/vm/src/obj/objmemory.rs @@ -20,7 +20,7 @@ impl PyMemoryView { try_as_byte(&self.obj_ref) } - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, bytes_object: PyObjectRef, diff --git a/vm/src/obj/objnamespace.rs b/vm/src/obj/objnamespace.rs index 931855e94..36518bbc7 100644 --- a/vm/src/obj/objnamespace.rs +++ b/vm/src/obj/objnamespace.rs @@ -19,7 +19,7 @@ impl PyValue for PyNamespace { #[pyimpl] impl PyNamespace { - #[pyslot(new)] + #[pyslot] fn tp_new(cls: PyClassRef, kwargs: KwArgs, vm: &VirtualMachine) -> PyResult> { let zelf = PyNamespace.into_ref_with_type(vm, cls)?; for (name, value) in kwargs.into_iter() { diff --git a/vm/src/obj/objnone.rs b/vm/src/obj/objnone.rs index 25201de4b..93f7385bd 100644 --- a/vm/src/obj/objnone.rs +++ b/vm/src/obj/objnone.rs @@ -37,7 +37,7 @@ impl IntoPyObject for Option { #[pyimpl] impl PyNone { - #[pyslot(new)] + #[pyslot] fn tp_new(_: PyClassRef, vm: &VirtualMachine) -> PyNoneRef { vm.ctx.none.clone() } diff --git a/vm/src/obj/objproperty.rs b/vm/src/obj/objproperty.rs index 441323d9e..ffa068d8c 100644 --- a/vm/src/obj/objproperty.rs +++ b/vm/src/obj/objproperty.rs @@ -131,7 +131,7 @@ impl PyBuiltinDescriptor for PyProperty { #[pyimpl] impl PyProperty { - #[pyslot(new)] + #[pyslot] fn tp_new(cls: PyClassRef, args: PropertyArgs, vm: &VirtualMachine) -> PyResult { PyProperty { getter: args.fget, diff --git a/vm/src/obj/objrange.rs b/vm/src/obj/objrange.rs index c3885beb9..28998962e 100644 --- a/vm/src/obj/objrange.rs +++ b/vm/src/obj/objrange.rs @@ -384,7 +384,7 @@ impl PyRange { pyhash::hash_iter(elements.iter(), vm) } - #[pyslot(new)] + #[pyslot] fn tp_new(args: PyFuncArgs, vm: &VirtualMachine) -> PyResult { let range = if args.args.len() <= 2 { let (cls, stop) = args.bind(vm)?; diff --git a/vm/src/obj/objset.rs b/vm/src/obj/objset.rs index 0da9d0edf..c433bbcc4 100644 --- a/vm/src/obj/objset.rs +++ b/vm/src/obj/objset.rs @@ -330,7 +330,7 @@ macro_rules! try_set_cmp { #[pyimpl] impl PySet { - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, iterable: OptionalArg, @@ -586,7 +586,7 @@ impl PySet { #[pyimpl] impl PyFrozenSet { - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, iterable: OptionalArg, diff --git a/vm/src/obj/objslice.rs b/vm/src/obj/objslice.rs index ae839248f..1eae01850 100644 --- a/vm/src/obj/objslice.rs +++ b/vm/src/obj/objslice.rs @@ -88,7 +88,7 @@ impl PySlice { } } - #[pyslot(new)] + #[pyslot] fn tp_new(cls: PyClassRef, args: PyFuncArgs, vm: &VirtualMachine) -> PyResult { let slice: PySlice = match args.args.len() { 0 => { diff --git a/vm/src/obj/objstaticmethod.rs b/vm/src/obj/objstaticmethod.rs index e6f74eebd..0fac69822 100644 --- a/vm/src/obj/objstaticmethod.rs +++ b/vm/src/obj/objstaticmethod.rs @@ -30,7 +30,7 @@ impl PyBuiltinDescriptor for PyStaticMethod { #[pyimpl] impl PyStaticMethodRef { - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, callable: PyObjectRef, diff --git a/vm/src/obj/objstr.rs b/vm/src/obj/objstr.rs index 1d5e4e9ba..1f299867c 100644 --- a/vm/src/obj/objstr.rs +++ b/vm/src/obj/objstr.rs @@ -179,7 +179,7 @@ struct StrArgs { #[pyimpl] impl PyString { - #[pyslot(new)] + #[pyslot] fn tp_new(cls: PyClassRef, args: StrArgs, vm: &VirtualMachine) -> PyResult { let string: PyStringRef = match args.object { OptionalArg::Present(input) => { diff --git a/vm/src/obj/objsuper.rs b/vm/src/obj/objsuper.rs index e4e31a84a..ba8b59664 100644 --- a/vm/src/obj/objsuper.rs +++ b/vm/src/obj/objsuper.rs @@ -76,7 +76,7 @@ impl PySuper { } } - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, py_type: OptionalArg, diff --git a/vm/src/obj/objtuple.rs b/vm/src/obj/objtuple.rs index 8e2e525a4..e39528f20 100644 --- a/vm/src/obj/objtuple.rs +++ b/vm/src/obj/objtuple.rs @@ -227,8 +227,8 @@ impl PyTuple { Ok(false) } - #[pyslot(new)] - fn tuple_new( + #[pyslot] + fn tp_new( cls: PyClassRef, iterable: OptionalArg, vm: &VirtualMachine, diff --git a/vm/src/obj/objweakproxy.rs b/vm/src/obj/objweakproxy.rs index befc30f1d..d4422868f 100644 --- a/vm/src/obj/objweakproxy.rs +++ b/vm/src/obj/objweakproxy.rs @@ -21,7 +21,7 @@ pub type PyWeakProxyRef = PyRef; #[pyimpl] impl PyWeakProxy { // TODO: callbacks - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, referent: PyObjectRef, diff --git a/vm/src/obj/objzip.rs b/vm/src/obj/objzip.rs index ace33f0c3..dc28133b8 100644 --- a/vm/src/obj/objzip.rs +++ b/vm/src/obj/objzip.rs @@ -20,7 +20,7 @@ impl PyValue for PyZip { #[pyimpl] impl PyZip { - #[pyslot(new)] + #[pyslot] fn tp_new(cls: PyClassRef, iterables: Args, vm: &VirtualMachine) -> PyResult { let iterators = iterables .into_iter() diff --git a/vm/src/stdlib/array.rs b/vm/src/stdlib/array.rs index 0565abf35..daa9b195d 100644 --- a/vm/src/stdlib/array.rs +++ b/vm/src/stdlib/array.rs @@ -190,7 +190,7 @@ impl PyValue for PyArray { #[pyimpl] impl PyArray { - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, spec: PyStringRef, diff --git a/vm/src/stdlib/collections.rs b/vm/src/stdlib/collections.rs index 4bf1a0e76..5448d6ed8 100644 --- a/vm/src/stdlib/collections.rs +++ b/vm/src/stdlib/collections.rs @@ -39,7 +39,7 @@ impl PyDeque { #[pyimpl] impl PyDeque { - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, iter: OptionalArg, diff --git a/vm/src/stdlib/hashlib.rs b/vm/src/stdlib/hashlib.rs index 291a3996b..5e4b49352 100644 --- a/vm/src/stdlib/hashlib.rs +++ b/vm/src/stdlib/hashlib.rs @@ -41,7 +41,7 @@ impl PyHasher { } } - #[pyslot(new)] + #[pyslot] fn tp_new(_cls: PyClassRef, _args: PyFuncArgs, vm: &VirtualMachine) -> PyResult { Ok(PyHasher::new("md5", HashWrapper::md5()) .into_ref(vm) diff --git a/vm/src/stdlib/itertools.rs b/vm/src/stdlib/itertools.rs index 63648d303..00828079b 100644 --- a/vm/src/stdlib/itertools.rs +++ b/vm/src/stdlib/itertools.rs @@ -31,7 +31,7 @@ impl PyValue for PyItertoolsChain { #[pyimpl] impl PyItertoolsChain { - #[pyslot(new)] + #[pyslot] fn tp_new(cls: PyClassRef, args: PyFuncArgs, vm: &VirtualMachine) -> PyResult> { PyItertoolsChain { iterables: args.args, @@ -103,7 +103,7 @@ impl PyValue for PyItertoolsCompress { #[pyimpl] impl PyItertoolsCompress { - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, data: PyObjectRef, @@ -154,7 +154,7 @@ impl PyValue for PyItertoolsCount { #[pyimpl] impl PyItertoolsCount { - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, start: OptionalArg, @@ -207,7 +207,7 @@ impl PyValue for PyItertoolsCycle { #[pyimpl] impl PyItertoolsCycle { - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, iterable: PyObjectRef, @@ -272,7 +272,7 @@ impl PyValue for PyItertoolsRepeat { #[pyimpl] impl PyItertoolsRepeat { - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, object: PyObjectRef, @@ -332,7 +332,7 @@ impl PyValue for PyItertoolsStarmap { #[pyimpl] impl PyItertoolsStarmap { - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, function: PyObjectRef, @@ -374,7 +374,7 @@ impl PyValue for PyItertoolsTakewhile { #[pyimpl] impl PyItertoolsTakewhile { - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, predicate: PyObjectRef, @@ -433,7 +433,7 @@ impl PyValue for PyItertoolsDropwhile { #[pyimpl] impl PyItertoolsDropwhile { - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, predicate: PyCallable, @@ -502,7 +502,7 @@ fn pyobject_to_opt_usize(obj: PyObjectRef, vm: &VirtualMachine) -> Option #[pyimpl] impl PyItertoolsIslice { - #[pyslot(new)] + #[pyslot] fn tp_new(cls: PyClassRef, args: PyFuncArgs, vm: &VirtualMachine) -> PyResult> { let (iter, start, stop, step) = match args.args.len() { 0 | 1 => { @@ -616,7 +616,7 @@ impl PyValue for PyItertoolsFilterFalse { #[pyimpl] impl PyItertoolsFilterFalse { - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, predicate: PyObjectRef, @@ -673,7 +673,7 @@ impl PyValue for PyItertoolsAccumulate { #[pyimpl] impl PyItertoolsAccumulate { - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, iterable: PyObjectRef, @@ -838,7 +838,7 @@ struct ProductArgs { #[pyimpl] impl PyItertoolsProduct { - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, iterables: Args, @@ -949,7 +949,7 @@ impl PyValue for PyItertoolsCombinations { #[pyimpl] impl PyItertoolsCombinations { - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, iterable: PyObjectRef, @@ -1048,7 +1048,7 @@ impl PyValue for PyItertoolsCombinationsWithReplacement { #[pyimpl] impl PyItertoolsCombinationsWithReplacement { - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, iterable: PyObjectRef, @@ -1144,7 +1144,7 @@ impl PyValue for PyItertoolsPermutations { #[pyimpl] impl PyItertoolsPermutations { - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, iterable: PyObjectRef, @@ -1277,7 +1277,7 @@ struct ZiplongestArgs { #[pyimpl] impl PyItertoolsZiplongest { - #[pyslot(new)] + #[pyslot] fn tp_new( cls: PyClassRef, iterables: Args, diff --git a/vm/src/stdlib/socket.rs b/vm/src/stdlib/socket.rs index c9dca0006..ba4a490ea 100644 --- a/vm/src/stdlib/socket.rs +++ b/vm/src/stdlib/socket.rs @@ -90,7 +90,7 @@ impl PySocket { self.sock.borrow() } - #[pyslot(new)] + #[pyslot] fn tp_new(cls: PyClassRef, _args: PyFuncArgs, vm: &VirtualMachine) -> PyResult> { PySocket { kind: Cell::default(),