[Python-ideas] @Override decorator

Ethan Furman ethan at stoneleaf.us
Tue Jul 19 00:29:49 EDT 2016

On 07/18/2016 09:04 PM, Guido van Rossum wrote:

> The same argument would apply against abstractmethod... I have definitely wondered when looking over some code whether it was defining or overriding a method. But requiring people to always decorate overrides seems hard, unless we made it a property that can be enforced by a metaclass, maybe?

Do you mean something like:

def __new__(metacls, cls, bases, clsdict):
     for name, attr in clsdict.items():
         if callable(attr):
              is_override = isinstance(attr, override)
              # search for name in bases
              # if found and is_override is False, raise
              # or if not found and is_override is True, raise


More information about the Python-ideas mailing list