core: migrate code to benefit from 3.9 stuff

for now keeping ruff on 3.8 target version, need to sort out modules as well
This commit is contained in:
Dima Gerasimov 2024-10-19 20:19:07 +01:00
parent d1511929a8
commit 721fd98dca
37 changed files with 413 additions and 302 deletions

View file

@ -1,4 +1,8 @@
from .internal import assert_subpackage; assert_subpackage(__name__)
from __future__ import annotations
from .internal import assert_subpackage
assert_subpackage(__name__)
import logging
import sys
@ -9,8 +13,6 @@ from typing import (
TYPE_CHECKING,
Any,
Callable,
Optional,
Type,
TypeVar,
Union,
cast,
@ -59,12 +61,12 @@ def _appdirs_cache_dir() -> Path:
_CACHE_DIR_NONE_HACK = Path('/tmp/hpi/cachew_none_hack')
def cache_dir(suffix: Optional[PathIsh] = None) -> Path:
def cache_dir(suffix: PathIsh | None = None) -> Path:
from . import core_config as CC
cdir_ = CC.config.get_cache_dir()
sp: Optional[Path] = None
sp: Path | None = None
if suffix is not None:
sp = Path(suffix)
# guess if you do need absolute, better path it directly instead of as suffix?
@ -143,21 +145,19 @@ if TYPE_CHECKING:
# we need two versions due to @doublewrap
# this is when we just annotate as @cachew without any args
@overload # type: ignore[no-overload-impl]
def mcachew(fun: F) -> F:
...
def mcachew(fun: F) -> F: ...
@overload
def mcachew(
cache_path: Optional[PathProvider] = ...,
cache_path: PathProvider | None = ...,
*,
force_file: bool = ...,
cls: Optional[Type] = ...,
cls: type | None = ...,
depends_on: HashFunction = ...,
logger: Optional[logging.Logger] = ...,
logger: logging.Logger | None = ...,
chunk_by: int = ...,
synthetic_key: Optional[str] = ...,
) -> Callable[[F], F]:
...
synthetic_key: str | None = ...,
) -> Callable[[F], F]: ...
else:
mcachew = _mcachew_impl