ITADN

`list.sort()` fails to detect type issue

#21646Openalexprengere 创建于 2026-06-25
bugtopic-overloadstopic-self-types
A
alexprengerecommented
This code is not failing under mypy: ```python [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 ```
1 条评论