From a4e1deb45882a873af19fb94e8c80fd122bce1af Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Tue, 8 Oct 2019 21:18:53 +0100 Subject: [PATCH] fix mypy, use more links to models --- README.md | 2 +- my/books/kobo.py | 13 ++----------- my/hypothesis.py | 1 - my/reddit.py | 22 +++++++++------------- 4 files changed, 12 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 2d72f68..d36c5fd 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Also read/run [demo.py](demo.py) for a full demonstration of setting up Hypothes ``` # see https://github.com/python/mypy/issues/1645 for --namespace-packages explanation -with_my --namespace-packages my/hypothesis.py +with_my --namespace-packages my ``` or, set up as `mypy.ini` file: ``` diff --git a/my/books/kobo.py b/my/books/kobo.py index 5edc338..7d2dd74 100644 --- a/my/books/kobo.py +++ b/my/books/kobo.py @@ -1,14 +1,5 @@ -from functools import lru_cache - -from .. import paths - -@lru_cache() -def kobuddy_module(): - from ..common import import_from - return import_from(paths.kobuddy.repo, 'kobuddy') - -kobuddy = kobuddy_module() -from kobuddy import * +from my_configuration import paths +from my_configuration.repos.kobuddy.src.kobuddy import * set_databases(paths.kobuddy.export_dir) diff --git a/my/hypothesis.py b/my/hypothesis.py index e34b9fb..25244bd 100644 --- a/my/hypothesis.py +++ b/my/hypothesis.py @@ -1,4 +1,3 @@ -from functools import lru_cache from pathlib import Path from my_configuration import paths diff --git a/my/reddit.py b/my/reddit.py index d444ced..36b67f3 100755 --- a/my/reddit.py +++ b/my/reddit.py @@ -1,14 +1,10 @@ #!/usr/bin/env python3 -from functools import lru_cache from pathlib import Path, PosixPath -from typing import List, Sequence +from typing import List, Sequence, Mapping -from . import paths +from my_configuration import paths +import my_configuration.repos.rexport.model as rexport -@lru_cache() -def rexport(): - from .common import import_file - return import_file(Path(paths.rexport.repo) / 'model.py') class CPath(PosixPath): def open(self, *args, **kwargs): @@ -24,7 +20,7 @@ def get_backup_files() -> Sequence[Path]: def get_model(): - model = rexport().Model(get_backup_files()) + model = rexport.Model(get_backup_files()) return model import logging @@ -33,8 +29,8 @@ def get_logger(): return logging.getLogger('my.reddit') -Save = rexport().Save -Sid = rexport().Sid +Save = rexport.Save +Sid = rexport.Sid def get_saves() -> List[Save]: @@ -94,7 +90,7 @@ def _get_state(bfile: Path) -> Dict[Sid, SaveWithDt]: bdt = _get_bdate(bfile) - saves = [SaveWithDt(save, bdt) for save in rexport().Model([bfile]).saved()] + saves = [SaveWithDt(save, bdt) for save in rexport.Model([bfile]).saved()] from kython import make_dict return make_dict( sorted(saves, key=lambda p: p.save.created), @@ -111,11 +107,11 @@ def _get_events(backups: Sequence[Path], parallel: bool) -> List[Event]: logger = get_logger() events: List[Event] = [] - prev_saves: Dict[Sid, Save] = {} + prev_saves: Mapping[Sid, Save] = {} # TODO suppress first batch?? # TODO for initial batch, treat event time as creation time - states: Iterable[Dict[Sid, Save]] + states: Iterable[Mapping[Sid, Save]] if parallel: with Pool() as p: states = p.map(_get_state, backups)