Skip to content

Fix PLW0129 for conditional expressions - #30434

Open
anshikagrover15 wants to merge 1 commit into
astral-sh:mainfrom
anshikagrover15:fix/plw0129-conditional-expression
Open

anshikagrover15 wants to merge 1 commit into
astral-sh:mainfrom
anshikagrover15:fix/plw0129-conditional-expression

Conversation

@anshikagrover15

Copy link
Copy Markdown

Summary

Fixes #30432.

Extend PLW0129 (assert-on-string-literal) to detect string literals in both branches of a top-level conditional expression used in an assert statement.

For example, assert value if condition else "fallback" should be flagged because one branch always evaluates to a non-empty string, making the assertion always pass.

The implementation reuses the existing string-literal diagnostic logic and checks only the direct branches of the conditional expression. Comparison-wrapped conditionals are left unchanged.

Added regression tests covering:

  • Non-empty strings in both branches.
  • Empty strings in both branches.
  • Conditional expressions inside comparisons, which should not be flagged.

Notes to reviewers

The focused test, formatting checks, prek checks, and git diff --check all pass.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PLW0129: also flag string-literals if they appear in the branch of a conditional expression in assert

1 participant