mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
Merge pull request #3197 from Snowapril/mapping_proxy_repr
Add missing `repr` for `mappingproxy`
This commit is contained in:
2
Lib/test/test_dataclasses.py
vendored
2
Lib/test/test_dataclasses.py
vendored
@@ -52,8 +52,6 @@ class TestCase(unittest.TestCase):
|
||||
class C:
|
||||
x: int = field(default=1, default_factory=int)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_field_repr(self):
|
||||
int_field = field(default=1, init=True, repr=False)
|
||||
int_field.name = "id"
|
||||
|
||||
4
Lib/test/test_pprint.py
vendored
4
Lib/test/test_pprint.py
vendored
@@ -323,8 +323,6 @@ OrderedDict([('the', 0),
|
||||
('lazy', 7),
|
||||
('dog', 8)])""")
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_mapping_proxy(self):
|
||||
words = 'the quick brown fox jumped over a lazy dog'.split()
|
||||
d = dict(zip(words, itertools.count()))
|
||||
@@ -657,8 +655,6 @@ frozenset2({0,
|
||||
self.assertEqual(pprint.pformat(dict.fromkeys(keys, 0)),
|
||||
'{%r: 0, %r: 0}' % tuple(sorted(keys, key=id)))
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_sort_orderable_and_unorderable_values(self):
|
||||
# Issue 22721: sorted pprints is not stable
|
||||
a = Unorderable()
|
||||
|
||||
@@ -137,6 +137,16 @@ impl PyMappingProxy {
|
||||
}
|
||||
}
|
||||
}
|
||||
#[pymethod(magic)]
|
||||
fn repr(&self, vm: &VirtualMachine) -> PyResult<String> {
|
||||
let obj = match &self.mapping {
|
||||
MappingProxyInner::Dict(d) => d.clone(),
|
||||
MappingProxyInner::Class(c) => {
|
||||
PyDict::from_attributes(c.attributes.read().clone(), vm)?.into_pyobject(vm)
|
||||
}
|
||||
};
|
||||
Ok(format!("mappingproxy({})", vm.to_repr(&obj)?))
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMapping for PyMappingProxy {
|
||||
|
||||
Reference in New Issue
Block a user