Skip to content

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

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

Closed
antonagestam opened this issue Jun 18, 2019 · 1 comment
Labels
bug mypy got something wrong priority-1-normal topic-final PEP 591

Comments

@antonagestam
Copy link
Contributor

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.

@antonagestam antonagestam 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 Jun 18, 2019
@ilevkivskyi
Copy link
Member

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

@ilevkivskyi ilevkivskyi 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 Jun 18, 2019
@ilevkivskyi ilevkivskyi added bug mypy got something wrong priority-1-normal labels Jun 18, 2019
@AlexWaygood AlexWaygood added the topic-final PEP 591 label Mar 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-1-normal topic-final PEP 591
Projects
None yet
Development

No branches or pull requests

4 participants