astral-sh / astral-sh/ruff

Rule for assert statements that are always true

Open
#9,750 1 comment 1 reaction 0 assignees View on GitHub
needs-decision rule
Dominant language
Rust
Stars
49.7k
Forks
2.4k
Avg merge
2d 1h
Merged PRs (30d)
458

Description

I have been searching the documentation, but I cannot seem to find a rule that checks for "tautologies" in assert statements. I recently had a case in my codebase where I had an assert statement in the form of:

```py
assert my_dict["key"] == my_dict["key"]
```

Whereas I wanted to have

```py
assert my_dict["key"] == expected_dict["key"]
```

A rule that would check for statements that are always true would be helpful, at the least for cases where we have an equality check of an item with itself.

Does such a rule exist? Should it be added?

Contributor guide

Open the contributing guide

Research direction

The issue names no implementation files or tests. Start by checking Ruff's existing assertion-related rules and their tests, then determine how a tautological equality in an assert should be diagnosed and what cases are considered done.

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.