Skip to content

[ty] add a lint rule to detect redundant assert statements#25204

Open
InvalidPathException wants to merge 2 commits into
astral-sh:mainfrom
InvalidPathException:main
Open

[ty] add a lint rule to detect redundant assert statements#25204
InvalidPathException wants to merge 2 commits into
astral-sh:mainfrom
InvalidPathException:main

Conversation

@InvalidPathException
Copy link
Copy Markdown
Contributor

Summary

Closes astral-sh/ty#3401

There are some assertions that are clearly always True/False and ty already has this information to support reasonably good detection.

This PR adds this (off by default) feature.

Test Plan

Added a test for type-based redundant assertion, and redundant assertions after augmented assignment like x-=1.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label May 17, 2026
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented May 17, 2026

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 89.36%. The percentage of expected errors that received a diagnostic held steady at 85.49%. The number of fully passing files held steady at 88/134.

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented May 17, 2026

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented May 17, 2026

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented May 17, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Check if an assert condition is always True

2 participants