mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
fix ass_subscript check
This commit is contained in:
@@ -37,7 +37,7 @@ impl Constructor for PyMappingProxy {
|
||||
type Args = PyObjectRef;
|
||||
|
||||
fn py_new(cls: PyTypeRef, mapping: Self::Args, vm: &VirtualMachine) -> PyResult {
|
||||
if !PyMapping::from(mapping.as_ref()).has_protocol(vm)
|
||||
if !PyMapping::from(mapping.as_ref()).check(vm)
|
||||
|| mapping.payload_if_subclass::<PyList>(vm).is_some()
|
||||
|| mapping.payload_if_subclass::<PyTuple>(vm).is_some()
|
||||
{
|
||||
|
||||
@@ -50,7 +50,7 @@ impl<'a> PyMapping<'a> {
|
||||
|
||||
pub fn try_protocol(obj: &'a PyObject, vm: &VirtualMachine) -> PyResult<Self> {
|
||||
let zelf = Self::from(obj);
|
||||
if zelf.has_protocol(vm) {
|
||||
if zelf.check(vm) {
|
||||
Ok(zelf)
|
||||
} else {
|
||||
Err(vm.new_type_error(format!("{} is not a mapping object", zelf.obj.class())))
|
||||
@@ -60,7 +60,7 @@ impl<'a> PyMapping<'a> {
|
||||
|
||||
impl PyMapping<'_> {
|
||||
// PyMapping::Check
|
||||
pub fn has_protocol(&self, vm: &VirtualMachine) -> bool {
|
||||
pub fn check(&self, vm: &VirtualMachine) -> bool {
|
||||
self.methods(vm).subscript.is_some()
|
||||
}
|
||||
|
||||
|
||||
@@ -464,8 +464,9 @@ impl PyObject {
|
||||
|
||||
let needle = needle.into_pyobject(vm);
|
||||
|
||||
if let Ok(mapping) = PyMapping::try_protocol(self, vm) {
|
||||
mapping.ass_subscript(&needle, Some(value), vm)
|
||||
let mapping = PyMapping::from(self);
|
||||
if let Some(f) = mapping.methods(vm).ass_subscript {
|
||||
f(&mapping, &needle, Some(value), vm)
|
||||
} else {
|
||||
// TODO: sequence protocol
|
||||
vm.get_special_method(self.to_owned(), "__setitem__")?
|
||||
@@ -491,8 +492,9 @@ impl PyObject {
|
||||
|
||||
let needle = needle.into_pyobject(vm);
|
||||
|
||||
if let Ok(mapping) = PyMapping::try_protocol(self, vm) {
|
||||
mapping.ass_subscript(&needle, None, vm)
|
||||
let mapping = PyMapping::from(self);
|
||||
if let Some(f) = mapping.methods(vm).ass_subscript {
|
||||
f(&mapping, &needle, None, vm)
|
||||
} else {
|
||||
//TODO: sequence protocol
|
||||
vm.get_special_method(self.to_owned(), "__delitem__")?
|
||||
|
||||
Reference in New Issue
Block a user