[Python-ideas] @Override decorator

Ben Finney ben+python at benfinney.id.au
Mon Jul 18 21:10:24 EDT 2016

Terry Reedy <tjreedy at udel.edu> writes:

> If you mean 'override' to have some actual function, then it is not
> clear to me. If the 'decorator' is strictly a comment, why not use a
> comment?

The primary behaviour I've seen for such suggestions is that ‘override’
will verify the method is already defined in the specified base class
(or, if no class specified, then in at least one of the base classes),
and if not will raise AssertionError.

The proposal describes the behaviour this way:

> >  2. With the advent of static typing from mypy:
> >      1. Having the decorator could corroborate the fact that the given
> >         method overrides the parent method correctly (correct name +
> >         parameter list).
> >      2. When the parent class changes, such as the name or parameter
> >         list of an abstract method, the children classes should be
> >         updated as well. mypy could easily target the methods that need
> >         to be altered with the correct method signature.
> >      3. If you don’t have an override decorator and overrode a parent
> >         method, then there could be some error complaining about this.
> >         This would be extremely useful to prevent accidental errors.

 \                              “Holy polar ice sheet, Batman!” —Robin |
  `\                                                                   |
_o__)                                                                  |
Ben Finney

More information about the Python-ideas mailing list