Skip to content
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

False positive for class method without Self annotation #15771

Open
tyralla opened this issue Jul 28, 2023 · 0 comments
Open

False positive for class method without Self annotation #15771

tyralla opened this issue Jul 28, 2023 · 0 comments
Labels
bug mypy got something wrong

Comments

@tyralla
Copy link
Collaborator

tyralla commented Jul 28, 2023

Mypy reports an error for method save1 (without annotation) but no errors for save2 and save3 (with different Self annotations), despite their (almost) identical function bodies:

from copy import deepcopy
from typing import Self

class A:
    states: list[Self]

    def save1(self) -> None:
        self.states.append(deepcopy(self))  # error: Argument 1 to "append" of "list" has incompatible type "A"; expected "Self"  [arg-type]

    def save2(self: Self) -> None:
        self.states.append(deepcopy(self))

    def save3(self) -> Self:
        self.states.append(deepcopy(self))
        return self

This bug might be related to #15529 but is not fixed by #15541.

Tasks

No tasks being tracked yet.
@tyralla tyralla added the bug mypy got something wrong label Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant