Skip to content

Suggestion: Having an @override decorator #1888

Description

@shreydesai

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions