mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Don't try to put __new__ on every type
This commit is contained in:
@@ -152,11 +152,6 @@ macro_rules! extend_class {
|
||||
$(
|
||||
$crate::extend_class!(@set_attr($ctx, $class, $name, $value));
|
||||
)*
|
||||
if $class.slots.borrow().new.is_some() {
|
||||
$class.attributes.borrow_mut().entry("__new__".into()).or_insert_with(|| {
|
||||
$ctx.new_classmethod($crate::obj::objtype::type_new)
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
(@set_attr($ctx:expr, $class:expr, (slot $slot_name:ident), $value:expr)) => {
|
||||
|
||||
@@ -158,6 +158,7 @@ pub fn init(context: &PyContext) {
|
||||
|
||||
extend_class!(context, object, {
|
||||
(slot new) => new_instance,
|
||||
"__new__" => context.new_classmethod(objtype::type_new),
|
||||
"__init__" => context.new_rustfunc(object_init),
|
||||
"__class__" =>
|
||||
PropertyBuilder::new(context)
|
||||
|
||||
@@ -294,11 +294,7 @@ fn type_new_slot(metatype: PyClassRef, args: PyFuncArgs, vm: &VirtualMachine) ->
|
||||
let mut bases: Vec<PyClassRef> = bases.iter(vm)?.collect::<Result<Vec<_>, _>>()?;
|
||||
bases.push(vm.ctx.object());
|
||||
|
||||
let mut attributes = dict.to_attributes();
|
||||
|
||||
attributes
|
||||
.entry("__new__".into())
|
||||
.or_insert_with(|| vm.ctx.new_classmethod(type_new));
|
||||
let attributes = dict.to_attributes();
|
||||
|
||||
let mut winner = metatype.clone();
|
||||
for base in &bases {
|
||||
|
||||
@@ -88,23 +88,21 @@ impl PyValue for PyItertoolsCompress {
|
||||
|
||||
#[pyimpl]
|
||||
impl PyItertoolsCompress {
|
||||
#[pymethod(name = "__new__")]
|
||||
#[allow(clippy::new_ret_no_self)]
|
||||
#[pyslot(new)]
|
||||
fn new(
|
||||
_cls: PyClassRef,
|
||||
cls: PyClassRef,
|
||||
data: PyObjectRef,
|
||||
selector: PyObjectRef,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult {
|
||||
) -> PyResult<PyRef<Self>> {
|
||||
let data_iter = get_iter(vm, &data)?;
|
||||
let selector_iter = get_iter(vm, &selector)?;
|
||||
|
||||
Ok(PyItertoolsCompress {
|
||||
PyItertoolsCompress {
|
||||
data: data_iter,
|
||||
selector: selector_iter,
|
||||
}
|
||||
.into_ref(vm)
|
||||
.into_object())
|
||||
.into_ref_with_type(vm, cls)
|
||||
}
|
||||
|
||||
#[pymethod(name = "__next__")]
|
||||
|
||||
Reference in New Issue
Block a user