Emit [mutable-override] for covariant override of attribute with method by brianschubert · Pull Request #18058 · python/mypy (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation2 Commits1 Checks18 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

brianschubert

Fixes #18052

Given:

flags: --enable-error-code=mutable-override

from typing import Callable

class Parent: func: Callable[[str], None]

class Child(Parent): def func(self, x: object) -> None: pass

Before:

Success: no issues found in 1 source file

After:

main.py:7 error: Covariant override of a mutable attribute (base class "Parent" defined the type as "Callable[[str], None]", override has type "Callable[[object], None]")
Found 1 error in 1 file (checked 1 source file)

@brianschubert

@github-actions GitHub Actions

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

hauntsaninja

@hauntsaninja

2 participants

@brianschubert @hauntsaninja