Skip to content

Commit 8df1c57

Browse files
authored
Merge pull request RustPython#3313 from DimitrisJim/mapping_check
Check if subscript is present for PyMapping::check.
2 parents 0ad892b + 9b63c50 commit 8df1c57

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

vm/src/builtins/mappingproxy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl Constructor for PyMappingProxy {
3737
type Args = PyObjectRef;
3838

3939
fn py_new(cls: PyTypeRef, mapping: Self::Args, vm: &VirtualMachine) -> PyResult {
40-
if !PyMapping::check(&mapping)
40+
if !PyMapping::check(&mapping, vm)
4141
|| mapping.payload_if_subclass::<PyList>(vm).is_some()
4242
|| mapping.payload_if_subclass::<PyTuple>(vm).is_some()
4343
{

vm/src/protocol/mapping.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ where
2626
T: Borrow<PyObjectRef>;
2727

2828
impl PyMapping<PyObjectRef> {
29-
pub fn check(obj: &PyObjectRef) -> bool {
29+
pub fn check(obj: &PyObjectRef, vm: &VirtualMachine) -> bool {
3030
obj.class()
3131
.mro_find_map(|x| x.slots.as_mapping.load())
32-
.is_some()
32+
.map(|f| f(obj, vm).subscript.is_some())
33+
.unwrap_or(false)
3334
}
3435

3536
pub fn methods(&self, vm: &VirtualMachine) -> PyMappingMethods {
@@ -119,7 +120,7 @@ impl IntoPyObject for PyMapping<PyObjectRef> {
119120

120121
impl TryFromObject for PyMapping<PyObjectRef> {
121122
fn try_from_object(vm: &VirtualMachine, mapping: PyObjectRef) -> PyResult<Self> {
122-
if Self::check(&mapping) {
123+
if Self::check(&mapping, vm) {
123124
Ok(Self::new(mapping))
124125
} else {
125126
Err(vm.new_type_error(format!("{} is not a mapping object", mapping.class())))

0 commit comments

Comments
 (0)