MCPcopy Create free account
hub / github.com/libgit2/pygit2 / GenericIterator

Class GenericIterator

pygit2/utils.py:204–225  ·  view source on GitHub ↗

Helper to easily implement an iterator. The constructor gets a container which must implement __len__ and __getitem__

Source from the content-addressed store, hash-verified

202
203
204class GenericIterator(Generic[T]):
205 """Helper to easily implement an iterator.
206
207 The constructor gets a container which must implement __len__ and
208 __getitem__
209 """
210
211 def __init__(self, container: SequenceProtocol[T]) -> None:
212 self.container = container
213 self.length = len(container)
214 self.idx = 0
215
216 def __iter__(self) -> Iterator[T]:
217 return self
218
219 def __next__(self) -> T:
220 idx = self.idx
221 if idx >= self.length:
222 raise StopIteration
223
224 self.idx += 1
225 return self.container[idx]

Callers 2

__iter__Method · 0.85
__iter__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…