Don't try to put __new__ on every type

This commit is contained in:
Noah
2019-09-27 11:13:35 -05:00
committed by coolreader18
parent b581975ef6
commit 2bb04f4836
4 changed files with 7 additions and 17 deletions

View File

@@ -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)) => {

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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__")]