Skip to content

Suggestion: Having an @override decorator #1888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
shreydesai opened this issue Jul 17, 2016 · 5 comments
Closed

Suggestion: Having an @override decorator #1888

shreydesai opened this issue Jul 17, 2016 · 5 comments

Comments

@shreydesai
Copy link
Contributor

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.

@refi64
Copy link
Contributor

refi64 commented Jul 17, 2016

I think this would be more of a Python library/language rather than something particular to mypy.

@gvanrossum
Copy link
Member

gvanrossum commented Jul 17, 2016

Yeah. Please use bugs.python.org or python-dev.

@gvanrossum
Copy link
Member

No, python-ideas

@timokau
Copy link

timokau commented 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
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants