diff options
author | Sebastian Thiel <sebastian.thiel@icloud.com> | 2021-06-18 11:28:33 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-18 11:28:33 +0800 |
commit | 6a0d131ece696f259e7ab42a064ceb10dabb1fcc (patch) | |
tree | fb07007006ec6af0dccbcd6a62abc4c6589dcfd3 /git/util.py | |
parent | b0f79c58ad919e90261d1e332df79a4ad0bc40de (diff) | |
parent | 18b6aa55309adfa8aa99bdaf9e8f80337befe74e (diff) | |
download | gitpython-6a0d131ece696f259e7ab42a064ceb10dabb1fcc.tar.gz |
Merge pull request #1271 from Yobmod/main
Add initial types to object, and fix CI
Diffstat (limited to 'git/util.py')
-rw-r--r-- | git/util.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/git/util.py b/git/util.py index edbd5f1e..516c315c 100644 --- a/git/util.py +++ b/git/util.py @@ -29,7 +29,7 @@ import pathlib if TYPE_CHECKING: from git.remote import Remote from git.repo.base import Repo -from .types import PathLike, TBD, Literal +from .types import PathLike, TBD, Literal, SupportsIndex # --------------------------------------------------------------------- @@ -971,7 +971,10 @@ class IterableList(list): # END for each item return list.__getattribute__(self, attr) - def __getitem__(self, index: Union[int, slice, str]) -> Any: + def __getitem__(self, index: Union[SupportsIndex, int, slice, str]) -> Any: + + assert isinstance(index, (int, str, slice)), "Index of IterableList should be an int or str" + if isinstance(index, int): return list.__getitem__(self, index) elif isinstance(index, slice): @@ -983,12 +986,13 @@ class IterableList(list): raise IndexError("No item found with id %r" % (self._prefix + index)) from e # END handle getattr - def __delitem__(self, index: Union[int, str, slice]) -> None: + def __delitem__(self, index: Union[SupportsIndex, int, slice, str]) -> Any: + + assert isinstance(index, (int, str)), "Index of IterableList should be an int or str" delindex = cast(int, index) if not isinstance(index, int): delindex = -1 - assert not isinstance(index, slice) name = self._prefix + index for i, item in enumerate(self): if getattr(item, self._id_attr) == name: |