Skip to content

Commit

Permalink
FIX: avoid Python 3.10 syntax (#492)
Browse files Browse the repository at this point in the history
* FIX: avoid `|` symbol in type hints on Python 3.9
* FIX: avoid `itertools.pairwise` call on Python 3.9
  • Loading branch information
redeboer authored Jan 17, 2025
1 parent 1c7151f commit 37de3c5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 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
2 changes: 1 addition & 1 deletion src/compwa_policy/utilities/pyproject/_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{
"build-system": NotRequired["BuildSystem"],
"project": "Project",
"dependency-groups": NotRequired[dict[str, list[str | IncludeGroup]]],
"dependency-groups": "NotRequired[dict[str, list[str | IncludeGroup]]]",
"tool": NotRequired[dict[str, dict[str, str]]],
},
)
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 37de3c5

Please sign in to comment.