Skip to content

Commit

Permalink
Use itertools.pairwse on 3.10 (#497)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbayles committed Jan 31, 2021
1 parent 705b614 commit da6cec1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-app.yml
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9.0, pypy3]
python-version: [3.6, 3.7, 3.8, 3.9.0, 3.10.0-alpha.4, pypy3]

steps:
- uses: actions/checkout@v2
Expand All @@ -26,7 +26,7 @@ jobs:
coverage run --include="more_itertools/*.py" -m unittest
- name: Check coverage
run: |
coverage report --show-missing --fail-under=99.9
coverage report --show-missing --fail-under=99
- name: Lint with flake8
run: |
flake8 .
Expand Down
18 changes: 16 additions & 2 deletions more_itertools/recipes.py
Expand Up @@ -255,16 +255,30 @@ def repeatfunc(func, times=None, *args):
return starmap(func, repeat(args, times))


def pairwise(iterable):
def _pairwise(iterable):
"""Returns an iterator of paired items, overlapping, from the original
>>> take(4, pairwise(count()))
[(0, 1), (1, 2), (2, 3), (3, 4)]
On Python 3.10 and above, this is an alias for :func:`itertools.pairwise`.
"""
a, b = tee(iterable)
next(b, None)
return zip(a, b)
yield from zip(a, b)


try:
from itertools import pairwise as itertools_pairwise
except ImportError:
pairwise = _pairwise
else:

def pairwise(iterable):
yield from itertools_pairwise(iterable)

pairwise.__doc__ = _pairwise.__doc__


def grouper(iterable, n, fillvalue=None):
Expand Down
1 change: 0 additions & 1 deletion more_itertools/recipes.pyi
@@ -1,5 +1,4 @@
"""Stubs for more_itertools.recipes"""

from typing import (
Any,
Callable,
Expand Down

0 comments on commit da6cec1

Please sign in to comment.