Skip to content
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

Support PEP 698 – Override Decorator #14072

Closed
2 tasks done
tmke8 opened this issue Nov 12, 2022 · 10 comments · Fixed by #14609 or #15512
Closed
2 tasks done

Support PEP 698 – Override Decorator #14072

tmke8 opened this issue Nov 12, 2022 · 10 comments · Fixed by #14609 or #15512
Labels
feature topic-inheritance Inheritance and incompatible overrides

Comments

@tmke8
Copy link
Contributor

tmke8 commented Nov 12, 2022

PEP 698 adds an @override decorator.

Todo:

Related issue: #1888

@tmke8 tmke8 added the feature label Nov 12, 2022
@JelleZijlstra JelleZijlstra added the topic-inheritance Inheritance and incompatible overrides label Nov 13, 2022
@tmke8
Copy link
Contributor Author

tmke8 commented Feb 2, 2023

The PEP has now been officially accepted for Python 3.12.

hauntsaninja pushed a commit that referenced this issue May 12, 2023
Closes #14072 

This implements support for [PEP
698](https://peps.python.org/pep-0698/), which has recently been
accepted for Python 3.12. However, this doesn't yet add the "strict
mode" that is recommended in the PEP.
@tmke8
Copy link
Contributor Author

tmke8 commented May 12, 2023

Ah, I shouldn't have linked this issue to the PR because there is still a missing piece: a new flag which enforces the use of @override on every overriding method ("strict mode").

@tmke8
Copy link
Contributor Author

tmke8 commented May 12, 2023

@hauntsaninja , can you reopen this issue? It seems I can't do that.

@NeilGirdhar
Copy link
Contributor

FYI: this discussion may be relevant for whoever implements the flag. 😄

@cdce8p
Copy link
Collaborator

cdce8p commented Jun 24, 2023

Just opened #15512 to add a strict flag for method overrides as suggested in the PEP.

@Avasam
Copy link
Contributor

Avasam commented Jul 10, 2023

I just noticed the Method "<method_name>" is marked as an override, but no base method was found with this name error is categorised under misc instead of override. Is that intended?

@mttbernardini
Copy link

There seems to be some issue with the way this plays with --check-untyped-defs, see this playground example:

from typing_extensions import override

class A:
    def f(self, x: int) -> int:
        return 2

class B(A):
    
    @override
    def f(self, x: int): # why `-> int` is not inferred?
        return None # why return type violation is not reported?
    
    @override
    def g(self, y): # why "no base method" is not reported?
        return 4

@bersbersbers
Copy link

Thanks, this is great! I have already added enable_error_code = ["explicit-override"] to enable it.

Are there plans for this error code to be included in strict mode any time soon?

@cdce8p
Copy link
Collaborator

cdce8p commented Jul 13, 2023

Are there plans for this error code to be included in strict mode any time soon?

I don't think that will happen. Just an example, enabling this for Home Assistant would create 11k+ new errors and that's just one project. It'll probably take quite a long time until all code is sufficiently updated, especially given that @override will only be added to the stdlib in Python 3.12.

@johnthagen
Copy link
Contributor

@bersbersbers I opened a tracking issue so that users can track when this is enabled by default in strict mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature topic-inheritance Inheritance and incompatible overrides
Projects
None yet
9 participants