File tree Expand file tree Collapse file tree 2 files changed +28
-7
lines changed Expand file tree Collapse file tree 2 files changed +28
-7
lines changed Original file line number Diff line number Diff line change @@ -151,12 +151,13 @@ class after this function is called.
151
151
" subclassing" )
152
152
153
153
abstracts = set ()
154
- # Check the existing abstract methods, keep only the ones that are
155
- # still abstract.
156
- for name in cls .__abstractmethods__ :
157
- value = getattr (cls , name , None )
158
- if getattr (value , "__isabstractmethod__" , False ):
159
- abstracts .add (name )
154
+ # Check the existing abstract methods of the parents, keep only the ones
155
+ # that are not implemented.
156
+ for scls in cls .__bases__ :
157
+ for name in getattr (scls , '__abstractmethods__' , ()):
158
+ value = getattr (cls , name , None )
159
+ if getattr (value , "__isabstractmethod__" , False ):
160
+ abstracts .add (name )
160
161
# Also add any other newly added abstract methods.
161
162
for name , value in cls .__dict__ .items ():
162
163
if getattr (value , "__isabstractmethod__" , False ):
Original file line number Diff line number Diff line change @@ -516,8 +516,8 @@ def updated_foo(self):
516
516
517
517
A .foo = updated_foo
518
518
abc .update_abstractmethods (A )
519
- msg = "class A with abstract methods bar, foo"
520
519
self .assertEqual (A .__abstractmethods__ , {'foo' , 'bar' })
520
+ msg = "class A with abstract methods bar, foo"
521
521
self .assertRaisesRegex (TypeError , msg , A )
522
522
523
523
def test_update_implementation (self ):
@@ -571,6 +571,26 @@ def updated_foo(self):
571
571
A ()
572
572
self .assertFalse (hasattr (A , '__abstractmethods__' ))
573
573
574
+ def test_update_del_implementation (self ):
575
+ class A (metaclass = abc_ABCMeta ):
576
+ @abc .abstractmethod
577
+ def foo (self ):
578
+ pass
579
+
580
+ class B (A ):
581
+ def foo (self ):
582
+ pass
583
+
584
+ B ()
585
+
586
+ del B .foo
587
+
588
+ abc .update_abstractmethods (B )
589
+
590
+ msg = "class B with abstract method foo"
591
+ self .assertRaisesRegex (TypeError , msg , B )
592
+
593
+
574
594
575
595
class TestABCWithInitSubclass (unittest .TestCase ):
576
596
def test_works_with_init_subclass (self ):
You can’t perform that action at this time.
0 commit comments