astral-sh / astral-sh/ruff

Rule suggestion: lint against the use of `in` with compound comparisons

Open
#8,964 2 comments 0 reactions 0 assignees View on GitHub
rule
Dominant language
Rust
Stars
49.6k
Forks
2.4k
Avg merge
2d 1h
Merged PRs (30d)
458

Description

The use of `in` with compound comparisons often leads to unintended/surprising behaviour.

```python
False == False in [False] # True
```

A solution would be to use parentheses.

```python
(False == False) in [False] # False
False == (False in [False]) # False
```

Similar to #8721, but the AST produced by `False or False and False` is quite different, so might be a different rule.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing issue #8721 and comparing the AST for compound comparisons with the examples shown here. Define the rule around surprising uses of `in` with compound comparisons, require parentheses as the remedy, and verify that the examples produce the intended diagnostics without overlapping the existing rule.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.