Skip to content

redundant-expr does not catch always-True if #19728

@A5rocks

Description

@A5rocks

Bug Report

If the expression for an if statement is always true, then it is obviously redundant.

To Reproduce

from typing import Literal

class X:
    def __bool__(self) -> Literal[True]:
        return True

if X():
    print("blah!")

Expected Behavior

Error on if X()

Actual Behavior

No error

Your Environment

  • Mypy version used: 1.17.1
  • Mypy command-line flags: --enable-error-code=redundant-expr
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.14

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-reachabilityDetecting unreachable code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions