Skip to content

Commit

Permalink
Try fixing Python < 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
behdad committed Dec 18, 2023
1 parent aaab754 commit c8a8b47
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions Lib/fontTools/misc/iterTools.py
@@ -0,0 +1,12 @@
from itertools import *

# Python 3.12:
if "batched" not in globals():
# https://docs.python.org/3/library/itertools.html#itertools.batched
def batched(iterable, n):
# batched('ABCDEFG', 3) --> ABC DEF G
if n < 1:
raise ValueError("n must be at least one")

Check warning on line 9 in Lib/fontTools/misc/iterTools.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/misc/iterTools.py#L9

Added line #L9 was not covered by tests
it = iter(iterable)
while batch := tuple(islice(it, n)):
yield batch
2 changes: 1 addition & 1 deletion Lib/fontTools/ttLib/scaleUpem.py
Expand Up @@ -14,7 +14,7 @@
from fontTools.varLib.multiVarStore import OnlineMultiVarStoreBuilder
from fontTools.misc.vector import Vector
from fontTools.misc.fixedTools import otRound
from itertools import batched
from fontTools.misc.iterTools import batched


__all__ = ["scale_upem", "ScalerVisitor"]
Expand Down
2 changes: 1 addition & 1 deletion Lib/fontTools/varLib/multiVarStore.py
Expand Up @@ -10,7 +10,7 @@
buildMultiVarStore,
buildMultiVarData,
)
from itertools import batched
from fontTools.misc.iterTools import batched
from functools import partial
from collections import defaultdict
from heapq import heappush, heappop
Expand Down

0 comments on commit c8a8b47

Please sign in to comment.