Skip to content

Commit a901323

Browse files
committed
Separate dict.__new__ to dict.__init__ for OrderedDict
1 parent 6553bf7 commit a901323

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

vm/src/obj/objdict.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use super::objstr;
66
use super::objtype::{self, PyClassRef};
77
use crate::dictdatatype::{self, DictKey};
88
use crate::exceptions::PyBaseExceptionRef;
9-
use crate::function::{KwArgs, OptionalArg};
9+
use crate::function::{KwArgs, OptionalArg, PyFuncArgs};
1010
use crate::pyobject::{
1111
IdProtocol, IntoPyObject, ItemProtocol, PyAttributes, PyClassImpl, PyContext, PyIterable,
1212
PyObjectRef, PyRef, PyResult, PyValue,
@@ -41,20 +41,21 @@ impl PyValue for PyDict {
4141
#[pyimpl(flags(BASETYPE))]
4242
impl PyDictRef {
4343
#[pyslot]
44-
fn tp_new(
45-
class: PyClassRef,
44+
fn tp_new(class: PyClassRef, _args: PyFuncArgs, vm: &VirtualMachine) -> PyResult<PyDictRef> {
45+
PyDict {
46+
entries: RefCell::new(DictContentType::default()),
47+
}
48+
.into_ref_with_type(vm, class)
49+
}
50+
51+
#[pymethod(magic)]
52+
fn init(
53+
self,
4654
dict_obj: OptionalArg<PyObjectRef>,
4755
kwargs: KwArgs,
4856
vm: &VirtualMachine,
49-
) -> PyResult<PyDictRef> {
50-
let dict = DictContentType::default();
51-
52-
let entries = RefCell::new(dict);
53-
// it's unfortunate that we can't abstract over RefCall, as we should be able to use dict
54-
// directly here, but that would require generic associated types
55-
PyDictRef::merge(&entries, dict_obj, kwargs, vm)?;
56-
57-
PyDict { entries }.into_ref_with_type(vm, class)
57+
) -> PyResult<()> {
58+
PyDictRef::merge(&self.entries, dict_obj, kwargs, vm)
5859
}
5960

6061
fn merge(

0 commit comments

Comments
 (0)