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

redundant-expr does not work with TypeVar with multiple constraints #18434

Open
kasium opened this issue Jan 10, 2025 · 0 comments
Open

redundant-expr does not work with TypeVar with multiple constraints #18434

kasium opened this issue Jan 10, 2025 · 0 comments
Labels
bug mypy got something wrong topic-type-variables

Comments

@kasium
Copy link

kasium commented Jan 10, 2025

Bug Report
A TypeVar with multiple constraints can be seen as a union. However, the redundant-expr does not understand it and emits errors which are wrong.

To Reproduce

from typing import TypeVar

T = TypeVar("T", int, str)

def foo(var: T) -> T:
    return "aa" if isinstance(var, str) else 0

Expected Behavior

no error

Actual Behavior

foo.py:9:20: error: If condition is always false  [redundant-expr]
        return "aa" if isinstance(var, str) else 0
                       ^~~~~~~~~~~~~~~~~~~~
foo.py:9:20: error: If condition is always true  [redundant-expr]
        return "aa" if isinstance(var, str) else 0
                       ^~~~~~~~~~~~~~~~~~~~
Found 2 errors in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.14.1
  • Mypy command-line flags: --enable-error-code redundant-expr
  • Python version used: 3.13.0
@kasium kasium added the bug mypy got something wrong label Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-type-variables
Projects
None yet
Development

No branches or pull requests

2 participants