diff --git a/Lib/test/test_patma.py b/Lib/test/test_patma.py index 5b2755f83..269e5f87e 100644 --- a/Lib/test/test_patma.py +++ b/Lib/test/test_patma.py @@ -42,7 +42,6 @@ class TestInheritance(unittest.TestCase): case [*_]: return "seq" - @unittest.expectedFailure # TODO: RUSTPYTHON def test_multiple_inheritance_mapping(self): class C: pass @@ -63,7 +62,6 @@ class TestInheritance(unittest.TestCase): self.assertEqual(self.check_mapping_then_sequence(M3()), "map") self.assertEqual(self.check_mapping_then_sequence(M4()), "map") - @unittest.expectedFailure # TODO: RUSTPYTHON def test_multiple_inheritance_sequence(self): class C: pass diff --git a/vm/src/builtins/type.rs b/vm/src/builtins/type.rs index 01ac2c1d6..cce580894 100644 --- a/vm/src/builtins/type.rs +++ b/vm/src/builtins/type.rs @@ -232,13 +232,25 @@ impl PyType { linearise_mro(mros) } - /// Inherit SEQUENCE and MAPPING flags from base class (CPython: inherit_patma_flags) - fn inherit_patma_flags(slots: &mut PyTypeSlots, base: &PyRef) { + /// Inherit SEQUENCE and MAPPING flags from base classes + /// Check all bases in order and inherit the first SEQUENCE or MAPPING flag found + fn inherit_patma_flags(slots: &mut PyTypeSlots, bases: &[PyRef]) { const COLLECTION_FLAGS: PyTypeFlags = PyTypeFlags::from_bits_truncate( PyTypeFlags::SEQUENCE.bits() | PyTypeFlags::MAPPING.bits(), ); - if !slots.flags.intersects(COLLECTION_FLAGS) { - slots.flags |= base.slots.flags & COLLECTION_FLAGS; + + // If flags are already set, don't override + if slots.flags.intersects(COLLECTION_FLAGS) { + return; + } + + // Check each base in order and inherit the first collection flag found + for base in bases { + let base_flags = base.slots.flags & COLLECTION_FLAGS; + if !base_flags.is_empty() { + slots.flags |= base_flags; + return; + } } } @@ -300,8 +312,8 @@ impl PyType { slots.flags |= PyTypeFlags::HAS_DICT } - // Inherit SEQUENCE and MAPPING flags from base class - Self::inherit_patma_flags(&mut slots, &base); + // Inherit SEQUENCE and MAPPING flags from base classes + Self::inherit_patma_flags(&mut slots, &bases); // Check for __abc_tpflags__ from ABCMeta (for collections.abc.Sequence, Mapping, etc.) Self::check_abc_tpflags(&mut slots, &attrs, &bases, ctx); @@ -359,7 +371,8 @@ impl PyType { } // Inherit SEQUENCE and MAPPING flags from base class - Self::inherit_patma_flags(&mut slots, &base); + // For static types, we only have a single base + Self::inherit_patma_flags(&mut slots, std::slice::from_ref(&base)); if slots.basicsize == 0 { slots.basicsize = base.slots.basicsize;