@@ -163,13 +163,16 @@ def prop(self):
163163class Slots (object ):
164164 __slots__ = ['s1' , 's2' , 's3' ]
165165
166- @property
167- def s3 (self ):
168- raise AssertionError ('Property __get__ executed' )
166+ if not py3 :
167+ @property
168+ def s3 (self ):
169+ raise AssertionError ('Property __get__ executed' )
169170
170171
171172class SlotsSubclass (Slots ):
172- pass
173+ @property
174+ def s4 (self ):
175+ raise AssertionError ('Property __get__ executed' )
173176
174177
175178member_descriptor = type (Slots .s1 )
@@ -208,19 +211,23 @@ def test_lookup_with_slots(self):
208211 inspection .safe_get_attribute (s , 's2' )
209212 self .assertIsInstance (inspection .safe_get_attribute_new_style (s , 's2' ),
210213 member_descriptor )
211- self .assertEquals (inspection .safe_get_attribute (s , 's3' ),
212- Slots .__dict__ ['s3' ])
213214
214215 def test_lookup_on_slots_classes (self ):
215216 sga = inspection .safe_get_attribute
216- self .assertIsInstance (inspection .safe_get_attribute (Slots , 's1' ),
217- member_descriptor )
218- self .assertIsInstance (inspection .safe_get_attribute (Slots , 's3' ),
219- property )
220- self .assertIsInstance (inspection .safe_get_attribute (SlotsSubclass , 's1' ),
221- member_descriptor )
222- self .assertIsInstance (inspection .safe_get_attribute (SlotsSubclass , 's3' ),
223- property )
217+ s = SlotsSubclass ()
218+ self .assertIsInstance (sga (Slots , 's1' ), member_descriptor )
219+ self .assertIsInstance (sga (SlotsSubclass , 's1' ), member_descriptor )
220+ self .assertIsInstance (sga (SlotsSubclass , 's4' ), property )
221+ self .assertIsInstance (sga (s , 's4' ), property )
222+
223+ @unittest .skipIf (py3 , "Python 3 doesn't allow slots and prop in same class" )
224+ def test_lookup_with_property_and_slots (self ):
225+ sga = inspection .safe_get_attribute
226+ s = SlotsSubclass ()
227+ self .assertIsInstance (sga (Slots , 's3' ), property )
228+ self .assertEquals (inspection .safe_get_attribute (s , 's3' ),
229+ Slots .__dict__ ['s3' ])
230+ self .assertIsInstance (sga (SlotsSubclass , 's3' ), property )
224231
225232if __name__ == '__main__' :
226233 unittest .main ()
0 commit comments