@@ -1320,6 +1320,32 @@ class X(object):
13201320 with self .assertRaisesRegex (AttributeError , "'X' object has no attribute 'a'" ):
13211321 X ().a
13221322
1323+ def test_slots_before_items (self ):
1324+ class C (type ):
1325+ __slots__ = ['a' ]
1326+ x = C ('A' , (int ,), {})
1327+ self .assertNotHasAttr (x , "a" )
1328+ x .a = 1
1329+ x .b = 2
1330+ self .assertEqual (x .a , 1 )
1331+ self .assertEqual (x .b , 2 )
1332+ self .assertNotIn ('a' , x .__dict__ )
1333+ self .assertIn ('b' , x .__dict__ )
1334+ del x .a
1335+ self .assertNotHasAttr (x , "a" )
1336+
1337+ @unittest .skipIf (_testcapi is None , 'need the _testcapi module' )
1338+ def test_slots_before_items2 (self ):
1339+ class D (_testcapi .HeapCCollection ):
1340+ __slots__ = ['a' ]
1341+ x = D (1 , 2 , 3 )
1342+ self .assertNotHasAttr (x , "a" )
1343+ x .a = 42
1344+ self .assertEqual (x .a , 42 )
1345+ del x .a
1346+ self .assertNotHasAttr (x , "a" )
1347+ self .assertEqual (list (x ), [1 , 2 , 3 ])
1348+
13231349 def test_slots_special (self ):
13241350 # Testing __dict__ and __weakref__ in __slots__...
13251351 class D (object ):
@@ -1384,14 +1410,6 @@ class W(_testcapi.HeapCCollection):
13841410 a .foo = 42
13851411 self .assertIs (weakref .ref (a )(), a )
13861412
1387- with self .assertRaises (TypeError ):
1388- class X (_testcapi .HeapCCollection ):
1389- __slots__ = ['x' ]
1390-
1391- with self .assertRaises (TypeError ):
1392- class X (_testcapi .HeapCCollection ):
1393- __slots__ = ['__dict__' , 'x' ]
1394-
13951413 @support .subTests (('base' , 'arg' ), [
13961414 (tuple , (1 , 2 , 3 )),
13971415 (int , 9876543210 ** 2 ),
0 commit comments