Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions pep-0698.rst
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,53 @@ hands of project owners, whereas the use of ``@require_explicit_overrides`` in
libraries would force project owners to use ``@override`` even if they prefer
not to.

Include the name of the ancestor class being overridden
-------------------------------------------------------

We considered allowing the caller of ``@override`` to specify a specific
ancestor class where the overridden method should be defined:

.. code-block:: python

class Parent0:
def foo() -> int:
return 1


class Parent1:
def bar() -> int:
return 1


class Child(Parent0, Parent1):
@override(Parent0) # okay, Parent0 defines foo
def foo() -> int:
return 2

@override(Parent0) # type error, Parent0 does not define bar
def bar() -> int:
return 2


This could be useful for code readability because it makes the override
structure more explicit for deep inheritance trees. It also might catch bugs by
prompting developers to check that the implementation of an override still makes
sense whenever a method being overridden moves from one base class to another.

We decided against it because:

- Supporting this would add complexity to the implementation of both
``@override`` and type checker support for it, so there would need to
be considerable value add.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be "added value"? I'm not sure I've ever heard "value add" in this way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit business jargony, means the same as "added value".

"Added value" may be clearer, or even "benefits".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I usually hear it with an indefinite article, i.e. "a considerable value add". From an editing perspective, if a change is going to be made, I agree with Hugo that it would be much clearer (especially to a wide, international audience) to just say "benefits".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, this wasn't great wording and "benefits" would be clearer. I can put that change up

- We believe that it would be rarely used and catch relatively few bugs.

- The author of the ``overrides`` package
`has noted <https://discuss.python.org/t/pep-698-a-typing-override-decorator/20839/4>`_
that early versions of his library included this capability but it was
rarely useful and seemed to have little benefit. After it was removed, the
ability was never requested by users.



Reference Implementation
========================
Expand Down