Skip to content

sorted() does not enforce comparable items in an iterable of tuples #13297

Closed as not planned
@jcmacdon

Description

@jcmacdon

sorted() does not enforce that every item in the tuple must be comparable:

items: list[tuple[int, object]] = [(1, object()), (1, object())]
sorted(items)

typeshed/stdlib/builtins.pyi

Lines 1762 to 1767 in e5c5318

@overload
def sorted(
iterable: Iterable[SupportsRichComparisonT], /, *, key: None = None, reverse: bool = False
) -> list[SupportsRichComparisonT]: ...
@overload
def sorted(iterable: Iterable[_T], /, *, key: Callable[[_T], SupportsRichComparison], reverse: bool = False) -> list[_T]: ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    reason: inexpressibleClosed, because this can't be expressed within the current type systemstubs: false negativeType checkers do not report an error, but should

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions