Skip to content

Commit 0d1b730

Browse files
authored
Update pyright to 1.110 (#19)
1 parent cdbbed5 commit 0d1b730

File tree

3 files changed

+44
-13
lines changed

3 files changed

+44
-13
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ repos:
2626
language: node
2727
pass_filenames: false
2828
types: [python]
29-
additional_dependencies: ["[email protected].104"]
29+
additional_dependencies: ["[email protected].110"]
3030
repo: local

expression/collections/seq.py

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,23 @@ def scan(self, scanner: Callable[[TState, TSource], TState], state: TState) -> I
230230
"""
231231
return Seq(itertools.accumulate(self, scanner, initial=state)) # type: ignore
232232

233+
def skip(self, count: int) -> Seq[TSource]:
234+
"""Returns a sequence that skips N elements of the underlying
235+
sequence and then yields the remaining elements of the sequence.
236+
237+
Args:
238+
count: The number of items to skip.
239+
"""
240+
return Seq(pipe(self, skip(count)))
241+
242+
def take(self, count: int) -> Seq[TSource]:
243+
"""Returns the first N elements of the sequence.
244+
245+
Args:
246+
count: The number of items to take.
247+
"""
248+
return Seq(pipe(self, take(count)))
249+
233250
@classmethod
234251
def unfold(cls, generator: Callable[[TState], Option[Tuple[TSource, TState]]], state: TState) -> Iterable[TSource]:
235252
"""Returns a list that contains the elements generated by the
@@ -677,6 +694,20 @@ def singleton(item: TSource) -> Seq[TSource]:
677694
return Seq([item])
678695

679696

697+
def skip(count: int) -> Projection[Any, Any]:
698+
"""Returns a sequence that skips N elements of the underlying
699+
sequence and then yields the remaining elements of the sequence.
700+
701+
Args:
702+
count: The number of items to skip.
703+
"""
704+
705+
def _skip(source: Iterable[TSource]) -> Iterable[TSource]:
706+
return (n for i, n in enumerate(source) if i >= count)
707+
708+
return _skip
709+
710+
680711
def take(count: int) -> Projection[Any, Any]:
681712
"""Returns the first N elements of the sequence.
682713
@@ -688,18 +719,7 @@ def take(count: int) -> Projection[Any, Any]:
688719
"""
689720

690721
def _take(source: Iterable[TSource]) -> Iterable[TSource]:
691-
n = count
692-
693-
def gen():
694-
nonlocal n
695-
for x in source:
696-
if n > 0:
697-
yield x
698-
n -= 1
699-
else:
700-
break
701-
702-
return gen()
722+
return (n for i, n in enumerate(source) if i < count)
703723

704724
return _take
705725

@@ -794,6 +814,7 @@ def _zip(source2: Iterable[TResult]) -> Iterable[Tuple[TSource, TResult]]:
794814
"of_iterable",
795815
"range",
796816
"scan",
817+
"skip",
797818
"singleton",
798819
"take",
799820
"Projection",

tests/test_seq.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,16 @@ def test_seq_collect(xs: List[int]):
188188
assert list(xs) == list(ys)
189189

190190

191+
@given(st.lists(st.integers()), st.integers(min_value=0))
192+
def test_seq_skip(xs: List[int], x: int):
193+
ys = seq.of_iterable(xs)
194+
try:
195+
zs = pipe(ys, seq.skip(x))
196+
assert list(zs) == xs[x:]
197+
except ValueError:
198+
assert x > len(xs)
199+
200+
191201
@given(st.lists(st.integers()), st.integers(min_value=0))
192202
def test_seq_take(xs: List[int], x: int):
193203
ys = seq.of_iterable(xs)

0 commit comments

Comments
 (0)