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

Binder fails to track loops correctly #18348

Closed
hauntsaninja opened this issue Dec 28, 2024 · 0 comments · Fixed by #18433
Closed

Binder fails to track loops correctly #18348

hauntsaninja opened this issue Dec 28, 2024 · 0 comments · Fixed by #18433
Labels
bug mypy got something wrong priority-0-high topic-type-narrowing Conditional type narrowing / binder

Comments

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Dec 28, 2024

# mypy: enable-error-code=redundant-expr
from __future__ import annotations

class Node:
    parent: Node | None
    is_valid: bool

    def traverse_needs_fixing(self) -> Node | None:
        it: Node | None
        it = self
        while it is not None and it.is_valid:  # E: Left operand of "and" is always true  [redundant-expr]
            it = it.parent
        return it

    def traverse(self) -> Node | None:
        # this only works because mypy does not narrow on initial assignment
        # which is something we'd like to change, see #2008
        it: Node | None = self
        while it is not None and it.is_valid:
            it = it.parent
        return it
@hauntsaninja hauntsaninja added bug mypy got something wrong topic-type-narrowing Conditional type narrowing / binder priority-0-high labels Dec 28, 2024
tyralla added a commit to tyralla/mypy that referenced this issue Jan 9, 2025
Fixes python#18348
Fixes python#13973
Fixes python#11612
Fixes python#8721
Fixes python#8865
Fixes python#7204

I manually checked all the listed issues.  Some of them were already partly fixed by python#18180.
hauntsaninja pushed a commit that referenced this issue Jan 12, 2025
…8433)

Fixes #18348
Fixes #13973
Fixes #11612
Fixes #8721
Fixes #8865
Fixes #7204

I manually checked all the listed issues. Some of them were already
partly fixed by #18180.
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-0-high topic-type-narrowing Conditional type narrowing / binder
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant