Mypy should warn about conditions whose value can be deduced
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Feature
Mypy can warn about left and right operands of conditions its value mypy can deduce. Unfortunately, it cannot do so for conditions consisting of one operand.
Pitch
val = 1337
if val is not None:
pass
if val is not None and True:
pass
Mypy can hint about the pointless left hand operand in the second if. Unfortunately, it does not do so for the first if. Supporting this use case would help the programmer to simplify her code by suggesting conditions to remove.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Begin with mypy's existing diagnostic for the pointless left-hand operand in the and True example, then locate the implementation and tests that produce it. Add coverage for the single-operand if val is not None case and verify mypy reports the removable condition without regressing the existing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100