Skip to content

Problem with sorted() and _LT #9582

@jolaf

Description

@jolaf

The following code:

from typing import Sequence
class A:
    pass
d: Sequence[A] = ()
s = sorted(d)
print("OK")

produces the following output:

$ python3 Test.py
OK
$ mypy Test.py
Test.py:8:5: error: Value of type variable "_LT" of "sorted" cannot be "A"  [type-var]
    s = sorted(d)
$ python3 --version
Python 3.8.5
$ mypy --version
mypy 0.790

The code seems perfectly valid, so mypy reaction looks a false positive.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions