Skip to content

Commit f9a17b0

Browse files
committed
Add: pyproperty dict values, items mapping
1 parent 5d0163e commit f9a17b0

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

vm/src/builtins/dict.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{
2-
set::PySetInner, IterStatus, PositionIterInternal, PyBaseExceptionRef, PyGenericAlias, PySet,
3-
PyStrRef, PyTupleRef, PyType, PyTypeRef, PyMappingProxy,
2+
set::PySetInner, IterStatus, PositionIterInternal, PyBaseExceptionRef, PyGenericAlias,
3+
PyMappingProxy, PySet, PyStrRef, PyTupleRef, PyType, PyTypeRef,
44
};
55
use crate::{
66
builtins::{
@@ -1095,6 +1095,10 @@ impl PyDictItems {
10951095
let found = PyDict::getitem(zelf.dict().clone(), key, vm)?;
10961096
vm.identical_or_equal(&found, &value)
10971097
}
1098+
#[pyproperty]
1099+
fn mapping(zelf: PyRef<Self>) -> PyMappingProxy {
1100+
PyMappingProxy::from(zelf.dict().clone())
1101+
}
10981102
}
10991103
impl Unconstructible for PyDictItems {}
11001104

@@ -1123,7 +1127,12 @@ impl AsSequence for PyDictItems {
11231127
}
11241128

11251129
#[pyimpl(with(DictView, Constructor, Iterable, AsSequence))]
1126-
impl PyDictValues {}
1130+
impl PyDictValues {
1131+
#[pyproperty]
1132+
fn mapping(zelf: PyRef<Self>) -> PyMappingProxy {
1133+
PyMappingProxy::from(zelf.dict().clone())
1134+
}
1135+
}
11271136
impl Unconstructible for PyDictValues {}
11281137

11291138
impl AsSequence for PyDictValues {

vm/src/builtins/mappingproxy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{PyDict, PyGenericAlias, PyList, PyTuple, PyType, PyTypeRef, PyDictRef};
1+
use super::{PyDict, PyDictRef, PyGenericAlias, PyList, PyTuple, PyType, PyTypeRef};
22
use crate::{
33
class::PyClassImpl,
44
convert::ToPyObject,
@@ -44,7 +44,7 @@ impl From<PyTypeRef> for PyMappingProxy {
4444

4545
impl From<PyDictRef> for PyMappingProxy {
4646
fn from(dict: PyDictRef) -> Self {
47-
Self {
47+
Self {
4848
mapping: MappingProxyInner::Mapping(ArgMapping::from_dict_exact(dict)),
4949
}
5050
}

0 commit comments

Comments
 (0)