mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
Merge pull request #3313 from DimitrisJim/mapping_check
Check if subscript is present for PyMapping::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::check(&mapping)
|
||||
if !PyMapping::check(&mapping, vm)
|
||||
|| mapping.payload_if_subclass::<PyList>(vm).is_some()
|
||||
|| mapping.payload_if_subclass::<PyTuple>(vm).is_some()
|
||||
{
|
||||
|
||||
@@ -26,10 +26,11 @@ where
|
||||
T: Borrow<PyObjectRef>;
|
||||
|
||||
impl PyMapping<PyObjectRef> {
|
||||
pub fn check(obj: &PyObjectRef) -> bool {
|
||||
pub fn check(obj: &PyObjectRef, vm: &VirtualMachine) -> bool {
|
||||
obj.class()
|
||||
.mro_find_map(|x| x.slots.as_mapping.load())
|
||||
.is_some()
|
||||
.map(|f| f(obj, vm).subscript.is_some())
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
pub fn methods(&self, vm: &VirtualMachine) -> PyMappingMethods {
|
||||
@@ -119,7 +120,7 @@ impl IntoPyObject for PyMapping<PyObjectRef> {
|
||||
|
||||
impl TryFromObject for PyMapping<PyObjectRef> {
|
||||
fn try_from_object(vm: &VirtualMachine, mapping: PyObjectRef) -> PyResult<Self> {
|
||||
if Self::check(&mapping) {
|
||||
if Self::check(&mapping, vm) {
|
||||
Ok(Self::new(mapping))
|
||||
} else {
|
||||
Err(vm.new_type_error(format!("{} is not a mapping object", mapping.class())))
|
||||
|
||||
Reference in New Issue
Block a user