Skip to content
Merged
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
20 changes: 9 additions & 11 deletions crates/stdlib/src/elementtree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ pub(crate) mod _elementtree {

#[pymethod]
fn makeelement(
zelf: &Py<Self>,
_zelf: &Py<Self>,
tag: PyObjectRef,
attrib: PyObjectRef,
vm: &VirtualMachine,
Expand All @@ -709,7 +709,7 @@ pub(crate) mod _elementtree {
))
})?;
let attrib = attrib.copy().into_ref(&vm.ctx);
create_element(zelf.class().to_owned(), tag, Some(attrib.into()), vm)
Ok(create_element(tag, Some(attrib.into()), vm))
}

#[pymethod]
Expand Down Expand Up @@ -837,7 +837,7 @@ pub(crate) mod _elementtree {
inner.children.clone(),
)
};
let new = create_element(zelf.class().to_owned(), tag, attrib, vm)?;
let new = create_element(tag, attrib, vm);
{
let elem = as_element(&new, vm)?;
let mut inner = elem.inner.write();
Expand Down Expand Up @@ -1068,16 +1068,14 @@ pub(crate) mod _elementtree {
.map_err(|_| vm.new_type_error("element indices must be integers"))
}

/// Instantiate `cls` (which may be an `Element` subclass) directly,
/// bypassing `__init__`, the way `create_new_element` does.
/// Create a base Element directly, bypassing `__init__`, like CPython's
/// `create_new_element`.
fn create_element(
cls: PyTypeRef,
tag: PyObjectRef,
attrib: Option<PyRef<PyAnyDict>>,
vm: &VirtualMachine,
) -> PyResult {
let element = PyElement::new(tag, attrib, vm);
Ok(element.into_ref_with_type(vm, cls)?.into())
) -> PyObjectRef {
PyElement::new(tag, attrib, vm).into_ref(&vm.ctx).into()
}

fn deepcopy_obj(obj: &PyObject, memo: &Py<PyDict>, vm: &VirtualMachine) -> PyResult {
Expand Down Expand Up @@ -1133,7 +1131,7 @@ pub(crate) mod _elementtree {
}
None => None,
};
let new = create_element(zelf.class().to_owned(), tag, attrib, vm)?;
let new = create_element(tag, attrib, vm);
let elem = as_element(&new, vm)?;
let text = deepcopy_obj(&text, memo, vm)?;
let tail = deepcopy_obj(&tail, memo, vm)?;
Expand Down Expand Up @@ -1304,7 +1302,7 @@ pub(crate) mod _elementtree {
))
})?;
let (tag, attrib) = parse_attrib_args(args, "SubElement", 1, vm)?;
let element = create_element(parent.class().to_owned(), tag, attrib.map(Into::into), vm)?;
let element = create_element(tag, attrib.map(Into::into), vm);
parent.push(element.clone());
Ok(element)
}
Expand Down
Loading