Pyright: Type inference failure in `sorted`

Created on 28 Oct 2019  路  3Comments  路  Source: microsoft/pyright

Describe the bug

from typing import List

a: List[str] = ["a", "bc"]
b: List[str] = sorted(a, key=len)

Causes an error:

4:16 - error: Expression of type 'List[Union[str, Sized]]' cannot be assigned to declared type 'List[str]'
  Type 'Sized' cannot be assigned to type 'str'
    'Sized' is incompatible with 'str'

version

1.0.81

addressed in next version bug

All 3 comments

Thanks for the bug report. I'm able to repro the problem, and I'll look into.

The fix will be in the next published version of pyright.

This is fixed in version 1.0.83, which I just published.

Was this page helpful?
0 / 5 - 0 ratings