`list.sort()` fails to detect type issue
Open
Nobody has claimed this yet.
bug
topic-overloads
topic-self-types
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
This code is not failing under mypy:
[2, None].sort()
Interestingly, it fails on ty:
error[invalid-argument-type]: Argument to bound method `list.sort` is incorrect
--> toto.py:1:1
|
1 | [None, 2].sort()
| ^^^^^^^^^^^^^^^^ Argument type `None | int` does not satisfy upper bound `SupportsDunderLT[Any] | SupportsDunderGT[Any]` of type variable `SupportsRichComparisonT`
|
info: Type variable defined here
--> stdlib/_typeshed/__init__.pyi:107:1
|
107 | SupportsRichComparisonT = TypeVar("SupportsRichComparisonT", bound=SupportsRichComparison) # noqa: Y001
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
Found 1 diagnostic
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
Reproduce the reported difference between mypy and ty with [2, None].sort(), then inspect the list.sort typing and the referenced stdlib/_typeshed/__init__.pyi definition. Determine the expected diagnostic and add regression coverage for the case, with the behavior made consistent with that expectation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 48/100