diff --git a/.github/workflows/run-tests.yaml b/.github/workflows/run-tests.yaml index d48a350..75178b1 100644 --- a/.github/workflows/run-tests.yaml +++ b/.github/workflows/run-tests.yaml @@ -20,6 +20,6 @@ jobs: fetch-depth: 0 - uses: actions/setup-python@v5 with: - python-version: '3.10' + python-version: '3.9' - name: Build & Test run: ./ci/build-test.sh diff --git a/src/rapids_pre_commit_hooks/copyright.py b/src/rapids_pre_commit_hooks/copyright.py index e93470b..64b56f8 100644 --- a/src/rapids_pre_commit_hooks/copyright.py +++ b/src/rapids_pre_commit_hooks/copyright.py @@ -95,7 +95,7 @@ def apply_copyright_check(linter, old_content): old_content, old_copyright_matches ) == strip_copyright(linter.content, new_copyright_matches): for old_match, new_match in zip( - old_copyright_matches, new_copyright_matches, strict=True + old_copyright_matches, new_copyright_matches ): if old_match.group() != new_match.group(): apply_copyright_revert(linter, old_match, new_match) diff --git a/src/rapids_pre_commit_hooks/lint.py b/src/rapids_pre_commit_hooks/lint.py index 3919030..16b9f6e 100644 --- a/src/rapids_pre_commit_hooks/lint.py +++ b/src/rapids_pre_commit_hooks/lint.py @@ -16,7 +16,6 @@ import bisect import contextlib import functools -import itertools import re import warnings @@ -24,6 +23,18 @@ from rich.markup import escape +# Taken from Python docs +# (https://docs.python.org/3.12/library/itertools.html#itertools.pairwise) +# Replace with itertools.pairwise after dropping Python 3.9 support +def _pairwise(iterable): + # pairwise('ABCDEFG') → AB BC CD DE EF FG + iterator = iter(iterable) + a = next(iterator, None) + for b in iterator: + yield a, b + a = b + + class OverlappingReplacementsError(RuntimeError): pass @@ -98,7 +109,7 @@ def fix(self): key=lambda replacement: replacement.pos, ) - for r1, r2 in itertools.pairwise(sorted_replacements): + for r1, r2 in _pairwise(sorted_replacements): if r1.pos[1] > r2.pos[0]: raise OverlappingReplacementsError(f"{r1} overlaps with {r2}") @@ -204,7 +215,9 @@ def __gt__(self, other): def __eq__(self, other): return self.pos[0] <= other <= self.pos[1] - line_index = bisect.bisect_left(self.lines, index, key=LineComparator) + line_index = bisect.bisect_left( + [LineComparator(line) for line in self.lines], index + ) try: line_pos = self.lines[line_index] except IndexError: