File tree Expand file tree Collapse file tree 3 files changed +21
-4
lines changed Expand file tree Collapse file tree 3 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -851,7 +851,11 @@ def __init__(self, obj):
851
851
except ImportError :
852
852
has_inline_values = None
853
853
854
- Py_TPFLAGS_MANAGED_DICT = (1 << 2 )
854
+
855
+ Py_TPFLAGS_MANAGED_DICT = (1 << 4 )
856
+
857
+ class NoManagedDict :
858
+ __slots__ = ('a' ,)
855
859
856
860
class Plain :
857
861
pass
@@ -865,11 +869,18 @@ def __init__(self):
865
869
self .c = 3
866
870
self .d = 4
867
871
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 )
870
875
871
876
# TODO: RUSTPYTHON
872
877
@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
+
873
884
def test_flags (self ):
874
885
self .assertEqual (Plain .__flags__ & Py_TPFLAGS_MANAGED_DICT , Py_TPFLAGS_MANAGED_DICT )
875
886
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 {
1053
1053
let heaptype_member_count = heaptype_slots. as_ref ( ) . map ( |x| x. len ( ) ) . unwrap_or ( 0 ) ;
1054
1054
let member_count: usize = base_member_count + heaptype_member_count;
1055
1055
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
+
1057
1062
let ( slots, heaptype_ext) = {
1058
1063
let slots = PyTypeSlots {
1059
1064
flags,
Original file line number Diff line number Diff line change @@ -122,6 +122,7 @@ bitflags! {
122
122
#[ derive( Copy , Clone , Debug , PartialEq ) ]
123
123
#[ non_exhaustive]
124
124
pub struct PyTypeFlags : u64 {
125
+ const MANAGED_DICT = 1 << 4 ;
125
126
const IMMUTABLETYPE = 1 << 8 ;
126
127
const HEAPTYPE = 1 << 9 ;
127
128
const BASETYPE = 1 << 10 ;
You can’t perform that action at this time.
0 commit comments