Skip to content

Failing type inference after sorted #2056

@bvolkmer

Description

@bvolkmer

Summary

Minimal example:

from pathlib import Path
from typing import reveal_type

foo: list[Path] = [Path("a"), Path("b"), Path("c")]
bar = sorted(foo, key=str)
reveal_type(foo)
reveal_type(sorted)
reveal_type(bar) 

For some reason, bar is revealed as list[Path | Buffer] where it should be list[Path]. It does not happen if key=str is omitted, even though also in this case the function generic of the return type depends on the input iterable: (iterable: Iterable[_T@sorted], *, /, key: (_T@sorted, /) -> SupportsDunderLT[Any] | SupportsDunderGT[Any], reverse: bool = False) -> list[_T@sorted]]

Version

ty 0.0.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions