File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -851,7 +851,11 @@ def __init__(self, obj):
851851except ImportError :
852852 has_inline_values = None
853853
854- Py_TPFLAGS_MANAGED_DICT = (1 << 2 )
854+
855+ Py_TPFLAGS_MANAGED_DICT = (1 << 4 )
856+
857+ class NoManagedDict :
858+ __slots__ = ('a' ,)
855859
856860class Plain :
857861 pass
@@ -865,11 +869,18 @@ def __init__(self):
865869 self .c = 3
866870 self .d = 4
867871
868-
869- class TestInlineValues (unittest .TestCase ):
872+ class TestNoManagedValues (unittest .TestCase ):
873+ def test_flags (self ):
874+ self .assertEqual (NoManagedDict .__flags__ & Py_TPFLAGS_MANAGED_DICT , 0 )
870875
871876 # TODO: RUSTPYTHON
872877 @unittest .expectedFailure
878+ def test_no_inline_values_for_slots_class (self ):
879+ c = NoManagedDict ()
880+ self .assertFalse (has_inline_values (c ))
881+
882+ class TestInlineValues (unittest .TestCase ):
883+
873884 def test_flags (self ):
874885 self .assertEqual (Plain .__flags__ & Py_TPFLAGS_MANAGED_DICT , Py_TPFLAGS_MANAGED_DICT )
875886 self .assertEqual (WithAttrs .__flags__ & Py_TPFLAGS_MANAGED_DICT , Py_TPFLAGS_MANAGED_DICT )
Original file line number Diff line number Diff line change @@ -1053,7 +1053,12 @@ impl Constructor for PyType {
10531053 let heaptype_member_count = heaptype_slots. as_ref ( ) . map ( |x| x. len ( ) ) . unwrap_or ( 0 ) ;
10541054 let member_count: usize = base_member_count + heaptype_member_count;
10551055
1056- let flags = PyTypeFlags :: heap_type_flags ( ) | PyTypeFlags :: HAS_DICT ;
1056+ let mut flags = PyTypeFlags :: heap_type_flags ( ) ;
1057+ // Only add HAS_DICT and MANAGED_DICT if __slots__ is not defined.
1058+ if heaptype_slots. is_none ( ) {
1059+ flags |= PyTypeFlags :: HAS_DICT | PyTypeFlags :: MANAGED_DICT ;
1060+ }
1061+
10571062 let ( slots, heaptype_ext) = {
10581063 let slots = PyTypeSlots {
10591064 flags,
Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments