Skip to content

Overriding final method only raises error if overriding method is annotated  #7015

Closed

Description

@antonagestam

In the code below I expected both subclasses to raise errors due to overriding method marked with @final, but only the B class raises an error, it seems like adding the return type annotation triggers the check. The same behavior is not specific to __init__ but happens with any method name.

from typing_extensions import final


class Base:
    @final
    def __init__(self):
        pass


class A(Base):
    def __init__(self):  # no error raised
        pass


class B(Base):
    def __init__(self) -> None:  # raises an error
        pass

setup.cfg:

[mypy]
ignore_missing_imports = True
strict_optional = True
no_implicit_optional = True
check_untyped_defs = True
disallow_incomplete_defs = True
disallow_any_unimported = True
disallow_untyped_decorators = True

Same result with both master mypy 0.710+dev.44172caa122b01af5a63ec5787931b910f272eb6 and latest stable mypy 0.701 using Python 3.7.0.

Activity

  1. changed the title [-]Bug: Final __init__ only raises error if sub-class __init__ is annotated [/-] [+]Bug: Overriding final method only raises error if overriding method is annotated [/+] on Jun 18, 2019
  2. ilevkivskyi commented on Jun 18, 2019

    @ilevkivskyi
    Member

    Yes, indeed, this happens with all methods, not just __init__(). I think mypy should give an error even for non-annotated methods.

  3. changed the title [-]Bug: Overriding final method only raises error if overriding method is annotated [/-] [+]Overriding final method only raises error if overriding method is annotated [/+] on Jun 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions