TypeError from sorting incompatible types isn't flagged
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
I was surprised that some code like this wasn't flagged by mypy:
[1, None].sort()
-
What is the actual behavior/output?
No error. -
What is the behavior/output you expect?
I would expect a similar warning as I get if I do1 > None
test.py:12: error: Unsupported operand types for > ("int" and "None")
-
What are the versions of mypy and Python you are using?
mypy 0.782, python 3.8.2 -
What are the mypy flags you are using? (For example --strict-optional)
follow_imports=normal
warn_redundant_casts=True
warn_unused_ignores=True
strict_optional=True
strict_equality=True
no_implicit_optional=True
disallow_untyped_defs=True
disallow_any_generics=True
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
No source file or test is named. Start by reproducing the two examples with mypy 0.782 and the listed flags, then trace how list.sort() is type-checked versus the comparison expression. Done means the incompatible element types in [1, None].sort() produce an appropriate diagnostic and a regression test covers the behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100