my.core: deprecate Path/dataclass imports from my.core during type checking

runtime still works for backwards compatibility
This commit is contained in:
Dima Gerasimov 2024-08-16 00:14:44 +03:00 committed by karlicoss
parent 7f8a502310
commit 2b0f92c883
10 changed files with 34 additions and 18 deletions

View file

@ -6,6 +6,7 @@ REQUIRES = ['ijson', 'cffi']
# NOTE likely also needs libyajl2 from apt or elsewhere?
from dataclasses import dataclass
from pathlib import Path
from typing import Sequence, Iterable, List, Optional
@ -22,8 +23,9 @@ def inputs() -> Sequence[Path]:
return get_files(user_config.logfiles)
from .core import dataclass, Json, PathIsh, datetime_aware
from .core.compat import fromisoformat
from my.core import Json, PathIsh, datetime_aware
from my.core.compat import fromisoformat
@dataclass

View file

@ -4,9 +4,10 @@ Parses active browser history by backing it up with [[http://github.com/seanbrec
REQUIRES = ["browserexport", "sqlite_backup"]
from dataclasses import dataclass
from my.config import browser as user_config
from my.core import Paths, dataclass
from my.core import Paths
@dataclass

View file

@ -1,4 +1,6 @@
# this file only keeps the most common & critical types/utility functions
from typing import TYPE_CHECKING
from .common import get_files, PathIsh, Paths
from .common import Json
from .stats import stat, Stats
@ -12,8 +14,10 @@ from .logging import make_logger, LazyLogger
from .util import __NOT_HPI_MODULE__
# just for brevity in modules
# todo not sure about these.. maybe best to rely on regular imports.. perhaps compare?
if not TYPE_CHECKING:
# we used to keep these here for brevity, but feels like it only adds confusion,
# e.g. suggest that we perhaps somehow modify builtin behaviour or whatever
# so best to prefer explicit behaviour
from dataclasses import dataclass
from pathlib import Path
@ -34,7 +38,7 @@ __all__ = [
'Res', 'unwrap',
'dataclass', 'Path', # TODO deprecate these from use in my.core
'dataclass', 'Path',
]

View file

@ -1,10 +1,13 @@
'''
Bindings for the 'core' HPI configuration
'''
from dataclasses import dataclass
from pathlib import Path
import re
from typing import Sequence, Optional
from . import warnings, PathIsh, Path
from . import warnings, PathIsh
try:
from my.config import core as user_config # type: ignore[attr-defined]
@ -21,7 +24,6 @@ except Exception as e:
_HPI_CACHE_DIR_DEFAULT = ''
from dataclasses import dataclass
@dataclass
class Config(user_config):
'''

View file

@ -15,10 +15,11 @@ the cachew cache
REQUIRES = ["git+https://github.com/seanbreckenridge/google_takeout_parser"]
from contextlib import ExitStack
from dataclasses import dataclass
import os
from typing import List, Sequence, cast
from pathlib import Path
from my.core import make_config, dataclass, stat, Stats
from my.core import make_config, stat, Stats
from my.core.cachew import mcachew
from my.core.common import LazyLogger, get_files, Paths
from my.core.error import ErrorPolicy

View file

@ -2,7 +2,8 @@
Last.fm scrobbles
'''
from my.core import Paths, dataclass, make_logger
from dataclasses import dataclass
from my.core import Paths, make_logger
from my.config import lastfm as user_config

View file

@ -4,9 +4,10 @@ Converts IP addresses provided by my.location.ip to estimated locations
REQUIRES = ["git+https://github.com/seanbreckenridge/ipgeocache"]
from dataclasses import dataclass
from datetime import timedelta
from my.core import dataclass, Stats, make_config
from my.core import Stats, make_config
from my.config import location
from my.core.warnings import medium

View file

@ -7,12 +7,13 @@ Extracts semantic location history using google_takeout_parser
REQUIRES = ["git+https://github.com/seanbreckenridge/google_takeout_parser"]
from dataclasses import dataclass
from typing import Iterator, List
from my.google.takeout.parser import events, _cachew_depends_on as _parser_cachew_depends_on
from google_takeout_parser.models import PlaceVisit as SemanticLocation
from my.core import dataclass, make_config, stat, LazyLogger, Stats
from my.core import make_config, stat, LazyLogger, Stats
from my.core.cachew import mcachew
from my.core.error import Res
from .common import Location

View file

@ -4,8 +4,11 @@ Parse [[https://github.com/mendhak/gpslogger][gpslogger]] .gpx (xml) files
REQUIRES = ["gpxpy"]
from dataclasses import dataclass
from my.config import location
from my.core import Paths, dataclass
from my.core import Paths
@dataclass

View file

@ -5,8 +5,9 @@ Stackexchange data (uses [[https://stackoverflow.com/legal/gdpr/request][officia
# TODO need to merge gdpr and stexport
### config
from dataclasses import dataclass
from my.config import stackexchange as user_config
from ..core import dataclass, PathIsh, make_config, get_files
from my.core import PathIsh, make_config, get_files, Json
@dataclass
class stackexchange(user_config):
gdpr_path: PathIsh # path to GDPR zip file
@ -16,8 +17,7 @@ config = make_config(stackexchange)
# TODO just merge all of them and then filter?.. not sure
from ..core.common import Json
from ..core.compat import fromisoformat
from my.core.compat import fromisoformat
from typing import NamedTuple, Iterable
from datetime import datetime
class Vote(NamedTuple):