add misc. stuff
authorJacob Lifshay <programmerjake@gmail.com>
Wed, 26 Oct 2022 05:30:46 +0000 (22:30 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Wed, 26 Oct 2022 05:30:46 +0000 (22:30 -0700)
src/bigint_presentation_code/util.py
src/bigint_presentation_code/util.pyi
typings/cached_property.pyi [new file with mode: 0644]

index b8b29344b6f6323b7d09414c653e1368bd9ed522..ef8c36c3533aaf66cca867a36b0913ae92281bb1 100644 (file)
@@ -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]):
index 6f12d4b971fae32b9ea8f0377a6fe6e5204e675b..0e0dbc72a21e734e6afa9282996b4dcc76d21a58 100644 (file)
@@ -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 (file)
index 0000000..b8b1f30
--- /dev/null
@@ -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: ...