facebook / facebook/pyrefly

report an error on unnecessary conditions

Open
#3,690 5 comments 0 reactions 0 assignees View on GitHub
typechecking
Dominant language
Rust
Stars
7k
Forks
516
PR merge metrics
No merged PRs in 30d

Description

```py
def fn(value: int):
if isinstance(value, int): # error
print(1)
```

this is comparable to reporting unreachable code (although it doesn't seem to work in cases like this anyway, see #3689), but the benefit of reporting an error on the condition is that it still warns you even if there's no other branch with unreachable code in it.

pyright has several rules for these:

- `reportUnnecessaryIsInstance`
- ~`reportUnnecessaryComparison`~ - covered by [`incompatible-comparison`](https://pyrefly.org/en/docs/error-kinds/#incompatible-comparison)
- `reportUnnecessaryContains`
- `reportAssertAlwaysTrue`

but ideally it should just be a generic rule that detects any unneccessary condition

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.