From: Jacob Lifshay Date: Wed, 26 Oct 2022 05:30:46 +0000 (-0700) Subject: add misc. stuff X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=219c2d4adbdfa736710b82d613cc63dac22016d9;p=bigint-presentation-code.git add misc. stuff --- diff --git a/src/bigint_presentation_code/util.py b/src/bigint_presentation_code/util.py index b8b2934..ef8c36c 100644 --- a/src/bigint_presentation_code/util.py +++ b/src/bigint_presentation_code/util.py @@ -1,8 +1,8 @@ -from typing import (TYPE_CHECKING, AbstractSet, Iterable, Iterator, Mapping, - MutableSet, TypeVar, Union) +from typing import (TYPE_CHECKING, AbstractSet, Any, Iterable, Iterator, + Mapping, MutableSet, NoReturn, TypeVar, Union) if TYPE_CHECKING: - from typing_extensions import Literal, final + from typing_extensions import Literal, Self, final else: def final(v): return v @@ -15,10 +15,19 @@ else: Literal = _Literal() + Self = Any + _T_co = TypeVar("_T_co", covariant=True) _T = TypeVar("_T") -__all__ = ["final", "Literal", "OFSet", "OSet", "FMap"] +__all__ = ["final", "Literal", "Self", "assert_never", "OFSet", "OSet", "FMap"] + + +# pyright currently doesn't like typing_extensions' definition +# -- added to typing in python 3.11 +def assert_never(arg): + # type: (NoReturn) -> NoReturn + raise AssertionError("got to code that's supposed to be unreachable") class OFSet(AbstractSet[_T_co]): diff --git a/src/bigint_presentation_code/util.pyi b/src/bigint_presentation_code/util.pyi index 6f12d4b..0e0dbc7 100644 --- a/src/bigint_presentation_code/util.pyi +++ b/src/bigint_presentation_code/util.pyi @@ -1,11 +1,18 @@ from typing import (AbstractSet, Iterable, Iterator, Mapping, - MutableSet, TypeVar, overload) -from typing_extensions import final, Literal + MutableSet, NoReturn, TypeVar, overload) +from typing_extensions import final, Literal, Self _T_co = TypeVar("_T_co", covariant=True) _T = TypeVar("_T") -__all__ = ["final", "Literal", "OFSet", "OSet", "FMap"] +__all__ = ["final", "Literal", "Self", "assert_never", "OFSet", "OSet", "FMap"] + + +# pyright currently doesn't like typing_extensions' definition +# -- added to typing in python 3.11 +def assert_never(arg): + # type: (NoReturn) -> NoReturn + raise AssertionError("got to code that's supposed to be unreachable") class OFSet(AbstractSet[_T_co]): diff --git a/typings/cached_property.pyi b/typings/cached_property.pyi new file mode 100644 index 0000000..b8b1f30 --- /dev/null +++ b/typings/cached_property.pyi @@ -0,0 +1,15 @@ +from typing import Any, Callable, Generic, TypeVar, overload + +_T = TypeVar("_T") + + +class cached_property(Generic[_T]): + def __init__(self, func: Callable[[Any], _T]) -> None: ... + + @overload + def __get__(self, instance: None, + owner: type[Any] | None = ...) -> cached_property[_T]: ... + + @overload + def __get__(self, instance: object, + owner: type[Any] | None = ...) -> _T: ...