mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Add support for star/stop values on index
See https://github.com/Textualize/textual/pull/1495#pullrequestreview-1238616797
This commit is contained in:
committed by
Rodrigo Girão Serrão
parent
2bf41fe428
commit
1e8162e8d0
@@ -1,6 +1,7 @@
|
|||||||
"""Provides an immutable sequence view class."""
|
"""Provides an immutable sequence view class."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
from sys import maxsize
|
||||||
from typing import Generic, TypeVar, Iterator, overload, Sequence
|
from typing import Generic, TypeVar, Iterator, overload, Sequence
|
||||||
|
|
||||||
T = TypeVar("T")
|
T = TypeVar("T")
|
||||||
@@ -47,11 +48,13 @@ class ImmutableSequenceView(Generic[T]):
|
|||||||
def __contains__(self, item: T) -> bool:
|
def __contains__(self, item: T) -> bool:
|
||||||
return item in self._wrap
|
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.
|
"""Return the index of the given item.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
item (T): The item to find in the sequence.
|
item (T): The item to find in the sequence.
|
||||||
|
start (int, optional): Optional start location.
|
||||||
|
stop (int, optional): Optional stop location.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
T: The index of the item in the sequence.
|
T: The index of the item in the sequence.
|
||||||
@@ -59,7 +62,7 @@ class ImmutableSequenceView(Generic[T]):
|
|||||||
Raises:
|
Raises:
|
||||||
ValueError: If the item is not in the sequence.
|
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]:
|
def __reversed__(self) -> Iterator[T]:
|
||||||
return reversed(self._wrap)
|
return reversed(self._wrap)
|
||||||
|
|||||||
Reference in New Issue
Block a user