debug variant parsing

This commit is contained in:
jgcodes2020 2024-12-24 09:49:53 -05:00
parent be667a2b9c
commit 96c5760eaf
3 changed files with 52 additions and 3 deletions

View file

@ -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