Skip to content

Commit ae53894

Browse files
committed
fix ass_subscript check
1 parent 6a996b0 commit ae53894

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
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::from(mapping.as_ref()).has_protocol(vm)
40+
if !PyMapping::from(mapping.as_ref()).check(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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl<'a> PyMapping<'a> {
5050

5151
pub fn try_protocol(obj: &'a PyObject, vm: &VirtualMachine) -> PyResult<Self> {
5252
let zelf = Self::from(obj);
53-
if zelf.has_protocol(vm) {
53+
if zelf.check(vm) {
5454
Ok(zelf)
5555
} else {
5656
Err(vm.new_type_error(format!("{} is not a mapping object", zelf.obj.class())))
@@ -60,7 +60,7 @@ impl<'a> PyMapping<'a> {
6060

6161
impl PyMapping<'_> {
6262
// PyMapping::Check
63-
pub fn has_protocol(&self, vm: &VirtualMachine) -> bool {
63+
pub fn check(&self, vm: &VirtualMachine) -> bool {
6464
self.methods(vm).subscript.is_some()
6565
}
6666

vm/src/protocol/object.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,9 @@ impl PyObject {
464464

465465
let needle = needle.into_pyobject(vm);
466466

467-
if let Ok(mapping) = PyMapping::try_protocol(self, vm) {
468-
mapping.ass_subscript(&needle, Some(value), vm)
467+
let mapping = PyMapping::from(self);
468+
if let Some(f) = mapping.methods(vm).ass_subscript {
469+
f(&mapping, &needle, Some(value), vm)
469470
} else {
470471
// TODO: sequence protocol
471472
vm.get_special_method(self.to_owned(), "__setitem__")?
@@ -491,8 +492,9 @@ impl PyObject {
491492

492493
let needle = needle.into_pyobject(vm);
493494

494-
if let Ok(mapping) = PyMapping::try_protocol(self, vm) {
495-
mapping.ass_subscript(&needle, None, vm)
495+
let mapping = PyMapping::from(self);
496+
if let Some(f) = mapping.methods(vm).ass_subscript {
497+
f(&mapping, &needle, None, vm)
496498
} else {
497499
//TODO: sequence protocol
498500
vm.get_special_method(self.to_owned(), "__delitem__")?

0 commit comments

Comments
 (0)