<div dir="ltr">Currently, the implementation of abstract methods is not possible outside of the class statement:<br><br>from abc import ABCMeta, abstractmethod<br>class ABC(metaclass=ABCMeta):<br> @abstractmethod<br> def method(self): pass<br>
class C(ABC): pass<br>C.method = lambda self: "actual implementation"<br>C()<br><br>results in
a TypeError (complaining about abstract methods), as __abstractmethods__ is just computed once, at class definition.<br><br>Of
course this example is a bit contrived, but perhaps a more legitimate
use case would involve a class decorator or another way to define the
implementation of the abstract methods out of the class, such as<br><br>@implementation(C, ABC)<br>def method():<br> return "actual implementation"<br><br>I
believe this behavior can be "fixed" (well, I don't know yet if this
should actually be considered an error, and haven't actually tried to
"fix" it) by defining ABCMeta.__setattr__ properly (to update
__abstractmethods__ when necessary). What do you think?<br><br>Best,<br>Antony</div>