general: move assert_never to my.core.compat as it's in stdlib from 3.11

rely on typing-extensions for fallback

introducing typing-extensions dependency without fallback, should be ok since it's in the top 10 of popular packages
This commit is contained in:
Dima Gerasimov 2024-08-12 15:45:59 +03:00
parent 1317914bff
commit 8834001fe7
10 changed files with 36 additions and 16 deletions

View file

@ -4,7 +4,7 @@ from .common import Json
from .common import warn_if_empty
from .common import stat, Stats
from .common import datetime_naive, datetime_aware
from .common import assert_never
from .compat import assert_never
from .cfg import make_config
from .error import Res, unwrap
@ -26,7 +26,7 @@ __all__ = [
'warn_if_empty',
'stat', 'Stats',
'datetime_aware', 'datetime_naive',
'assert_never',
'assert_never', # TODO maybe deprecate from use in my.core? will be in stdlib soon
'make_config',
@ -34,7 +34,7 @@ __all__ = [
'Res', 'unwrap',
'dataclass', 'Path',
'dataclass', 'Path', # TODO deprecate these from use in my.core
]

View file

@ -27,7 +27,10 @@ from typing import (
get_origin,
)
import warnings
from . import warnings as core_warnings
from . import compat
from .compat import deprecated
# some helper functions
PathIsh = Union[Path, str]
@ -633,11 +636,6 @@ class DummyExecutor(Executor):
self._shutdown = True
# see https://hakibenita.com/python-mypy-exhaustive-checking#exhaustiveness-checking
def assert_never(value: NoReturn) -> NoReturn:
assert False, f'Unhandled value: {value} ({type(value).__name__})'
def _check_all_hashable(fun):
# TODO ok, take callable?
hints = get_type_hints(fun)
@ -693,6 +691,13 @@ def unique_everseen(
## legacy imports, keeping them here for backwards compatibility
## hiding behind TYPE_CHECKING so it works in runtime
## in principle, warnings.deprecated decorator should cooperate with mypy, but doesn't look like it works atm?
## perhaps it doesn't work when it's used from typing_extensions
if not TYPE_CHECKING:
assert_never = deprecated('use my.core.compat.assert_never instead')(compat.assert_never)
# TODO wrap in deprecated decorator as well?
from functools import cached_property as cproperty
from typing import Literal
from .cachew import mcachew

View file

@ -121,3 +121,15 @@ if sys.version_info[:2] >= (3, 10):
from types import NoneType
else:
NoneType = type(None)
if sys.version_info[:2] >= (3, 13):
from warnings import deprecated
else:
from typing_extensions import deprecated
if sys.version_info[:2] >= (3, 11):
from typing import assert_never
else:
from typing_extensions import assert_never

View file

@ -9,7 +9,8 @@ from tempfile import TemporaryDirectory
from typing import Tuple, Any, Iterator, Callable, Optional, Union, Literal
from .common import PathIsh, assert_never
from .common import PathIsh
from .compat import assert_never
def sqlite_connect_immutable(db: PathIsh) -> sqlite3.Connection: