Skip to content

Commit ff35dcd

Browse files
authored
feat(vm/slot): implement Py_TPFLAGS_MANAGED_DICT for class objects (#5949)
1 parent 5284b73 commit ff35dcd

File tree

6 files changed

+7
-12
lines changed

6 files changed

+7
-12
lines changed

Lib/test/test_array.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,8 +1285,6 @@ def check_overflow(self, lower, upper):
12851285
self.assertRaises(OverflowError, array.array, self.typecode, [upper+1])
12861286
self.assertRaises(OverflowError, a.__setitem__, 0, upper+1)
12871287

1288-
# TODO: RUSTPYTHON
1289-
@unittest.expectedFailure
12901288
def test_subclassing(self):
12911289
typecode = self.typecode
12921290
class ExaggeratingArray(array.array):

Lib/test/test_importlib/test_metadata_api.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ def test_entry_points_missing_name(self):
139139
def test_entry_points_missing_group(self):
140140
assert entry_points(group='missing') == ()
141141

142-
# TODO: RUSTPYTHON
143-
@unittest.expectedFailure
144142
def test_entry_points_allows_no_attributes(self):
145143
ep = entry_points().select(group='entries', name='main')
146144
with self.assertRaises(AttributeError):

Lib/test/test_property.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,6 @@ class PropertySubSlots(property):
242242

243243
class PropertySubclassTests(unittest.TestCase):
244244

245-
# TODO: RUSTPYTHON
246-
@unittest.expectedFailure
247245
def test_slots_docstring_copy_exception(self):
248246
try:
249247
class Foo(object):

Lib/test/test_weakref.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,8 +1132,6 @@ class MyRef(weakref.ref):
11321132
self.assertIn(r1, refs)
11331133
self.assertIn(r2, refs)
11341134

1135-
# TODO: RUSTPYTHON
1136-
@unittest.expectedFailure
11371135
def test_subclass_refs_with_slots(self):
11381136
class MyRef(weakref.ref):
11391137
__slots__ = "slot1", "slot2"

vm/src/builtins/type.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,9 +1038,6 @@ impl Constructor for PyType {
10381038
});
10391039
}
10401040

1041-
// TODO: Flags is currently initialized with HAS_DICT. Should be
1042-
// updated when __slots__ are supported (toggling the flag off if
1043-
// a class has __slots__ defined).
10441041
let heaptype_slots: Option<PyRef<PyTuple<PyStrRef>>> =
10451042
if let Some(x) = attributes.get(identifier!(vm, __slots__)) {
10461043
let slots = if x.class().is(vm.ctx.types.str_type) {
@@ -1072,7 +1069,12 @@ impl Constructor for PyType {
10721069
let heaptype_member_count = heaptype_slots.as_ref().map(|x| x.len()).unwrap_or(0);
10731070
let member_count: usize = base_member_count + heaptype_member_count;
10741071

1075-
let flags = PyTypeFlags::heap_type_flags() | PyTypeFlags::HAS_DICT;
1072+
let mut flags = PyTypeFlags::heap_type_flags();
1073+
// Only add HAS_DICT and MANAGED_DICT if __slots__ is not defined.
1074+
if heaptype_slots.is_none() {
1075+
flags |= PyTypeFlags::HAS_DICT | PyTypeFlags::MANAGED_DICT;
1076+
}
1077+
10761078
let (slots, heaptype_ext) = {
10771079
let slots = PyTypeSlots {
10781080
flags,

vm/src/types/slot.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ bitflags! {
122122
#[derive(Copy, Clone, Debug, PartialEq)]
123123
#[non_exhaustive]
124124
pub struct PyTypeFlags: u64 {
125+
const MANAGED_DICT = 1 << 4;
125126
const IMMUTABLETYPE = 1 << 8;
126127
const HEAPTYPE = 1 << 9;
127128
const BASETYPE = 1 << 10;

0 commit comments

Comments
 (0)