mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
debug variant parsing
This commit is contained in:
parent
be667a2b9c
commit
96c5760eaf
3 changed files with 52 additions and 3 deletions
|
@ -19,6 +19,7 @@
|
|||
|
||||
import typing as T
|
||||
from dataclasses import dataclass
|
||||
import itertools
|
||||
|
||||
|
||||
class Colors:
|
||||
|
@ -154,3 +155,17 @@ def unescape_quote(string: str) -> str:
|
|||
i += 1
|
||||
|
||||
return result
|
||||
|
||||
def iter_batched(iterable, n, *, strict=False):
|
||||
"""
|
||||
Replacement for `itertools.batched()` since the testing infrastructure
|
||||
uses Python 3.9 at the moment. Copied directly off of the Python docs.
|
||||
"""
|
||||
# batched('ABCDEFG', 3) → ABC DEF G
|
||||
if n < 1:
|
||||
raise ValueError('n must be at least one')
|
||||
iterator = iter(iterable)
|
||||
while batch := tuple(itertools.islice(iterator, n)):
|
||||
if strict and len(batch) != n:
|
||||
raise ValueError('batched(): incomplete batch')
|
||||
yield batch
|
Loading…
Add table
Add a link
Reference in a new issue