Skip to content

Commit

Permalink
Add support for star/stop values on index
Browse files Browse the repository at this point in the history
  • Loading branch information
davep authored and rodrigogiraoserrao committed Jan 7, 2023
1 parent 2bf41fe commit 1e8162e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/textual/_immutable_sequence_view.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Provides an immutable sequence view class."""

from __future__ import annotations
from sys import maxsize
from typing import Generic, TypeVar, Iterator, overload, Sequence

T = TypeVar("T")
Expand Down Expand Up @@ -47,19 +48,21 @@ def __bool__(self) -> bool:
def __contains__(self, item: T) -> bool:
return item in self._wrap

def index(self, item: T) -> int:
def index(self, item: T, start: int = 0, stop: int = maxsize) -> int:
"""Return the index of the given item.
Args:
item (T): The item to find in the sequence.
start (int, optional): Optional start location.
stop (int, optional): Optional stop location.
Returns:
T: The index of the item in the sequence.
Raises:
ValueError: If the item is not in the sequence.
"""
return self._wrap.index(item)
return self._wrap.index(item, start, stop)

def __reversed__(self) -> Iterator[T]:
return reversed(self._wrap)

0 comments on commit 1e8162e

Please sign in to comment.