Closed
Description
Is there any interest in providing an @override decorator for base classes that re-implement (override) the functions of abstract classes? It could be potentially helpful in distinguishing between the functions that are inherited vs. functions that are unique to a class.
from abc import ABCMeta, abstractmethod
class A(metaclass=ABCMeta):
@abstractmethod
def f(self) -> None: pass
class B(A):
@override
def f(self) -> None:
print('Overridden function')
def g(self) -> None:
print('Non-overridden function')There seem to be rough implementations of such a decorator here - http://stackoverflow.com/questions/1167617/in-python-how-do-i-indicate-im-overriding-a-method.
Reacted by j, Yaroslav Pankovych, Sandy Fraser, 6harat 5olo, Paul Johnson, Oleg Schwann, no longer on github, etern and Laurenz
Metadata
Metadata
Assignees
Labels
No labels
Activity
refi64 commentedon Jul 17, 2016
I think this would be more of a Python library/language rather than something particular to mypy.
gvanrossum commentedon Jul 17, 2016
Yeah. Please use bugs.python.org or python-dev.
gvanrossum commentedon Jul 17, 2016
No, python-ideas
timokau commentedon May 2, 2020
For future reference: There is a continuation, unfortunately without conclusion, at https://mail.python.org/pipermail/python-ideas/2016-July/041095.html .
mkorpela commentedon May 24, 2020
Hi,
I would really like this to be also part of mypy typechecking. The implementation that I have https://github.com/mkorpela/overrides is a module load time check but moving this to even earlier pre-execution phase would in my opinion be great!