@@ -3175,6 +3175,8 @@ class A:
3175
3175
with self .assertRaisesRegex (TypeError ,
3176
3176
"cannot create weak reference" ):
3177
3177
weakref .ref (a )
3178
+ with self .assertRaises (AttributeError ):
3179
+ a .__weakref__
3178
3180
3179
3181
def test_slots_weakref (self ):
3180
3182
@dataclass (slots = True , weakref_slot = True )
@@ -3183,7 +3185,9 @@ class A:
3183
3185
3184
3186
self .assertIn ("__weakref__" , A .__slots__ )
3185
3187
a = A (1 )
3186
- weakref .ref (a )
3188
+ a_ref = weakref .ref (a )
3189
+
3190
+ self .assertIs (a .__weakref__ , a_ref )
3187
3191
3188
3192
def test_slots_weakref_base_str (self ):
3189
3193
class Base :
@@ -3249,7 +3253,8 @@ class A(Base):
3249
3253
self .assertIn ("__weakref__" , Base .__slots__ )
3250
3254
self .assertNotIn ("__weakref__" , A .__slots__ )
3251
3255
a = A (1 )
3252
- weakref .ref (a )
3256
+ a_ref = weakref .ref (a )
3257
+ self .assertIs (a .__weakref__ , a_ref )
3253
3258
3254
3259
def test_weakref_slot_subclass_no_weakref_slot (self ):
3255
3260
@dataclass (slots = True , weakref_slot = True )
@@ -3265,7 +3270,8 @@ class A(Base):
3265
3270
self .assertIn ("__weakref__" , Base .__slots__ )
3266
3271
self .assertNotIn ("__weakref__" , A .__slots__ )
3267
3272
a = A (1 )
3268
- weakref .ref (a )
3273
+ a_ref = weakref .ref (a )
3274
+ self .assertIs (a .__weakref__ , a_ref )
3269
3275
3270
3276
def test_weakref_slot_normal_base_weakref_slot (self ):
3271
3277
class Base :
@@ -3280,7 +3286,8 @@ class A(Base):
3280
3286
self .assertIn ("__weakref__" , Base .__slots__ )
3281
3287
self .assertNotIn ("__weakref__" , A .__slots__ )
3282
3288
a = A (1 )
3283
- weakref .ref (a )
3289
+ a_ref = weakref .ref (a )
3290
+ self .assertIs (a .__weakref__ , a_ref )
3284
3291
3285
3292
3286
3293
class TestDescriptors (unittest .TestCase ):
0 commit comments