Get the position of an entry or raise :exc:`ValueError`. :param key: The key to be looked up. .. versionchanged:: 0.5 This used to raise :exc:`IndexError`, which was inconsistent with the list API.
(self, key: str | tuple[str, float])
| 108 | return f"{type(self).__name__}([{pairs_str}])" |
| 109 | |
| 110 | def index(self, key: str | tuple[str, float]) -> int: # type: ignore[override] |
| 111 | """Get the position of an entry or raise :exc:`ValueError`. |
| 112 | |
| 113 | :param key: The key to be looked up. |
| 114 | |
| 115 | .. versionchanged:: 0.5 |
| 116 | This used to raise :exc:`IndexError`, which was inconsistent |
| 117 | with the list API. |
| 118 | """ |
| 119 | if isinstance(key, str): |
| 120 | for idx, (item, _quality) in enumerate(self): |
| 121 | if self._value_matches(key, item): |
| 122 | return idx |
| 123 | raise ValueError(key) |
| 124 | return list.index(self, key) |
| 125 | |
| 126 | def find(self, key: str | tuple[str, float]) -> int: |
| 127 | """Get the position of an entry or return -1. |