compat fix for test_field_metadata_custom_mapping in test_dataclasses.py

This commit is contained in:
hydrogen602
2024-04-17 01:00:59 -05:00
committed by Jeong, YunWon
parent 4d05416ce3
commit 6c37e8f4e7
2 changed files with 5 additions and 8 deletions

View File

@@ -1843,8 +1843,6 @@ class TestCase(unittest.TestCase):
'does not support item assignment'):
fields(C)[0].metadata['test'] = 3
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_field_metadata_custom_mapping(self):
# Try a custom mapping.
class SimpleNameSpace:

View File

@@ -93,13 +93,12 @@ impl Constructor for PyMappingProxy {
))]
impl PyMappingProxy {
fn get_inner(&self, key: PyObjectRef, vm: &VirtualMachine) -> PyResult<Option<PyObjectRef>> {
let opt = match &self.mapping {
MappingProxyInner::Class(class) => key
match &self.mapping {
MappingProxyInner::Class(class) => Ok(key
.as_interned_str(vm)
.and_then(|key| class.attributes.read().get(key).cloned()),
MappingProxyInner::Mapping(mapping) => mapping.mapping().subscript(&*key, vm).ok(),
};
Ok(opt)
.and_then(|key| class.attributes.read().get(key).cloned())),
MappingProxyInner::Mapping(mapping) => mapping.mapping().subscript(&*key, vm).map(Some),
}
}
#[pymethod]