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

@ -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,10 +14,12 @@ 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?
from dataclasses import dataclass
from pathlib import Path
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
__all__ = [
@ -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):
'''