core: cleanup itertool style helpers

- deprecate group_by_key, should use itertool.bucket instead
- move make_dict and ensure_unique to my.core.utils.itertools
This commit is contained in:
Dima Gerasimov 2024-08-13 10:22:39 +03:00 committed by karlicoss
parent 973c4205df
commit c64d7f5b67
7 changed files with 119 additions and 93 deletions

View file

@ -17,10 +17,10 @@ from typing import NamedTuple, List, Optional, Iterator, Sequence
from my.core import LazyLogger, get_files, Paths, PathIsh
from my.core.cachew import mcachew
from my.core.cfg import Attrs, make_config
from my.core.common import group_by_key
from my.core.error import Res, split_errors
from more_itertools import bucket
import pdfannots
@ -169,7 +169,9 @@ def annotated_pdfs(*, filelist: Optional[Sequence[PathIsh]]=None) -> Iterator[Re
ait = annotations()
vit, eit = split_errors(ait, ET=Exception)
for k, g in group_by_key(vit, key=lambda a: a.path).items():
bucketed = bucket(vit, key=lambda a: a.path)
for k in bucketed:
g = list(bucketed[k])
yield Pdf(path=Path(k), annotations=g)
yield from eit