Skip to content

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

Closed
@antonagestam

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions