Skip to content

0.750 regression: Incompatible types with enumerate()/sorted() and property #8064

@The-Compiler

Description

@The-Compiler

With 0.750 and this code:

from typing import TypeVar, Sequence

_T = TypeVar('_T')


class NeighborList:

    def __init__(self, items: Sequence[_T]) -> None:
        self._items = items

    def print_sorted(self) -> None:
        print(sorted(enumerate(self.items), key=lambda e: e[1]))  # <---

    @property
    def items(self) -> Sequence[_T]:
        return self._items


nl = NeighborList([1, 2, 3])
nl.print_sorted()

I get:

x.py:12: error: Argument 1 to "sorted" has incompatible type "enumerate[_T]"; expected "Iterable[Tuple[int, _T]]"
x.py:12: error: Argument 1 to "enumerate" has incompatible type "Sequence[_T]"; expected "Iterable[_T]"

I bisected this, it was introduced in 9d5d0e9 (part of #7933, fix for #7863).

When I remove the property and use self._items directly, things seem to be fine.

#7434 looks somewhat similar to me, but I don't think it's the same issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions