Skip to content

Support PEP 698 – Override Decorator #14072

Description

@tmke8

PEP 698 adds an @override decorator.

Todo:

Related issue: #1888

Activity

  1. tmke8 commented on Feb 2, 2023

    @tmke8
    ContributorAuthor

    The PEP has now been officially accepted for Python 3.12.

  2. added a commit that references this issue on May 12, 2023
    c1fb57d
  3. tmke8 commented on May 12, 2023

    @tmke8
    ContributorAuthor

    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").

  4. tmke8 commented on May 12, 2023

    @tmke8
    ContributorAuthor

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

  5. NeilGirdhar commented on May 12, 2023

    @NeilGirdhar
    Contributor

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

  6. cdce8p commented on Jun 24, 2023

    @cdce8p
    Collaborator

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

  7. Avasam commented on Jul 10, 2023

    @Avasam
    SponsorContributor

    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?

  8. mttbernardini commented on Jul 12, 2023

    @mttbernardini

    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
  9. added a commit that references this issue on Jul 13, 2023
    dfea43f
  10. bersbersbers commented on Jul 13, 2023

    @bersbersbers

    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?

  11. cdce8p commented on Jul 13, 2023

    @cdce8p
    Collaborator

    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.

  12. johnthagen commented on Jul 9, 2024

    @johnthagen
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions