Skip to content

Commit

Permalink
Add pure implementation of list.index
Browse files Browse the repository at this point in the history
  • Loading branch information
pschanely committed Nov 9, 2023
1 parent 1cbbf5d commit a5aa555
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions crosshair/libimpl/builtinslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -4310,8 +4310,27 @@ def _int_from_bytes(
return val


def _list_index(self, value, start=0, stop=9223372036854775807):
return list.index(self, value, realize(start), realize(stop))
_LIST_INDEX_START_DEFAULT = 0
_LIST_INDEX_STOP_DEFAULT = 9223372036854775807


def _list_index(
self, value, start=_LIST_INDEX_START_DEFAULT, stop=_LIST_INDEX_STOP_DEFAULT
):
with NoTracing():
if not isinstance(self, list):
raise TypeError
if (
start is not _LIST_INDEX_START_DEFAULT
or stop is not _LIST_INDEX_STOP_DEFAULT
):
self = self[start:stop]
for idx, self_value in enumerate(self):
with ResumedTracing():
isequal = value == self_value
if isequal:
return idx
raise ValueError


def _dict_get(self: dict, key, default=None):
Expand Down

0 comments on commit a5aa555

Please sign in to comment.