[Python-ideas] method decorators @final and @override in Python 2.4

Ben Finney ben+python at benfinney.id.au
Sat Mar 28 23:41:44 CET 2009

Péter Szabó <ptspts at gmail.com> writes:

> If Python had method decorators @final (meaning: it is an error to
> override this method in any subclass)

What use case is there for this? It would have to be quite strong to
override the Python philosophy that “we're all consenting adults
here”, and that the programmer of the subclass is the one who knows
best whether a method needs overriding.

> and @override (meaning: it is an error not having this method in a
> superclass)

I'm not sure I understand this one, but if I'm right this is supported
now with:

    class FooABC(object):
        def frobnicate(self):
            raise NotImplementedError("Must be implemented in derived class")

Or perhaps:

    class FooABC(object):
        def __init__(self):
            if self.frobnicate is NotImplemented:
                raise ValueError("Must override 'frobnicate' in derived class")

        frobnicate = NotImplemented

But, again, what is the use case? Is it strong enough to take away the
ability of the derived class's implementor (who is, remember, a
consenting adult) to take what they want from a class and leave the

 \             “We can't depend for the long run on distinguishing one |
  `\         bitstream from another in order to figure out which rules |
_o__)               apply.” —Eben Moglen, _Anarchism Triumphant_, 1999 |
Ben Finney

More information about the Python-ideas mailing list