KEMBAR78
Emit `[mutable-override]` for covariant override of attribute with method by brianschubert · Pull Request #18058 · python/mypy · GitHub
Skip to content

Conversation

brianschubert
Copy link
Member

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)

@github-actions
Copy link
Contributor

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

@hauntsaninja hauntsaninja merged commit 7f09f0c into python:master Oct 27, 2024
19 checks passed
@hauntsaninja
Copy link
Collaborator

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Overriding callable attribute with method not caught by [mutable-override]

2 participants