From anonymous, 7 Months ago, written in Python.
Embed
  1. from typing import TypeVar, Sequence
  2.  
  3. _T = TypeVar('_T')
  4.  
  5.  
  6. class NeighborList:
  7.  
  8.     def __init__(self, items: Sequence[_T]) -> None:
  9.         self._items = items
  10.  
  11.     def print_sorted(self) -> None:
  12.         print(sorted(enumerate(self.items), key=lambda e: e[1]))
  13.         # x.py:11: error: Argument 1 to "sorted" has incompatible type "enumerate[_T]"; expected "Iterable[Tuple[int, _T]]"
  14.         # x.py:11: error: Argument 1 to "enumerate" has incompatible type "Sequence[_T]"; expected "Iterable[_T]"
  15.  
  16.     @property
  17.     def items(self) -> Sequence[_T]:
  18.         return self._items
  19.  
  20.  
  21. nl = NeighborList([1, 2, 3])
  22. nl.print_sorted()
  23.