core: more type annotations

This commit is contained in:
Dima Gerasimov 2020-10-03 13:15:15 +01:00 committed by karlicoss
parent 44b756cc6b
commit 06ee72bc30
7 changed files with 43 additions and 34 deletions

View file

@ -12,7 +12,7 @@ from typing import Sequence, Iterable
from .core import get_files, LazyLogger
from .core.common import mcachew
from .core.error import Res, split_errors
from .core.pandas import check_dataframe as cdf
from .core.pandas import check_dataframe as cdf, DataFrameT
from my.config import rescuetime as config
@ -36,7 +36,7 @@ def entries() -> Iterable[Res[Entry]]:
yield from dal.entries()
def groups(gap=timedelta(hours=3)) -> Iterable[Res[Sequence[Entry]]]:
def groups(gap: timedelta=timedelta(hours=3)) -> Iterable[Res[Sequence[Entry]]]:
vit, eit = split_errors(entries(), ET=Exception)
yield from eit
import more_itertools
@ -45,7 +45,7 @@ def groups(gap=timedelta(hours=3)) -> Iterable[Res[Sequence[Entry]]]:
@cdf
def dataframe():
def dataframe() -> DataFrameT:
import pandas as pd # type: ignore
# type: ignore[call-arg, attr-defined]
def it():
@ -57,8 +57,8 @@ def dataframe():
return pd.DataFrame(it())
def stats():
from .core import stat
from .core import stat, Stats
def stats() -> Stats:
return {
**stat(groups),
**stat(entries),
@ -67,10 +67,11 @@ def stats():
# basically, hack config and populate it with fake data? fake data generated by DAL, but the rest is handled by this?
from typing import Iterator
from contextlib import contextmanager
# todo take seed, or what?
@contextmanager
def fake_data(rows=1000):
def fake_data(rows: int=1000) -> Iterator[None]:
# todo also disable cachew automatically for such things?
# TODO right, disabled_cachew won't work here because at that point, entries() is already wrapped?
# I guess need to fix this in cachew?