Skip to content

Commit

Permalink
FIX: avoid itertools.pairwise call on Python 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed Jan 17, 2025
1 parent 1c7151f commit f61076d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies = [
"rtoml", # fast, read-only parsing
"ruamel.yaml", # better YAML dumping
"tomlkit", # preserve original TOML formatting
'more-itertools; python_version <"3.10.0"', # pairwise
'typing-extensions; python_version <"3.12.0"', # override
]
description = "Pre-commit hooks that ensure that ComPWA repositories have a similar developer set-up"
Expand Down
10 changes: 7 additions & 3 deletions src/compwa_policy/utilities/pyproject/setters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from __future__ import annotations

import itertools
import re
import sys
from collections import abc
from typing import TYPE_CHECKING, Any, cast

Expand All @@ -15,6 +15,10 @@
)
from compwa_policy.utilities.toml import to_toml_array

if sys.version_info >= (3, 10):
from itertools import pairwise
else:
from more_itertools import pairwise
if TYPE_CHECKING:
from collections.abc import Iterable, Mapping, MutableMapping, Sequence

Expand Down Expand Up @@ -63,7 +67,7 @@ def _add_to_dependency_group(
return True
if isinstance(dependency_group, abc.Sequence) and len(dependency_group):
updated = add_dependency(pyproject, package, dependency_group[0])
for previous, current in itertools.pairwise(dependency_group):
for previous, current in pairwise(dependency_group):
dependencies = dependency_groups.get(current, [])
expected: IncludeGroup = {"include-group": previous}
if expected in dependencies:
Expand Down Expand Up @@ -97,7 +101,7 @@ def _add_to_optional_dependencies(
this_package = get_package_name(pyproject, raise_on_missing=True)
updated = False
updated &= add_dependency(pyproject, package, optional_key=optional_key[0])
for previous, key in itertools.pairwise(optional_key):
for previous, key in pairwise(optional_key):
updated &= add_dependency(
pyproject, f"{this_package}[{previous}]", optional_key=key
)
Expand Down

0 comments on commit f61076d

Please sign in to comment.