|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | from types import ModuleType as Namespace |
4 | | -from typing import TYPE_CHECKING, Literal, Protocol, TypeAlias, TypedDict, TypeVar |
| 4 | +from typing import ( |
| 5 | + TYPE_CHECKING, |
| 6 | + Literal, |
| 7 | + Protocol, |
| 8 | + TypeAlias, |
| 9 | + TypedDict, |
| 10 | + TypeVar, |
| 11 | + final, |
| 12 | +) |
5 | 13 |
|
6 | 14 | if TYPE_CHECKING: |
7 | 15 | from _typeshed import Incomplete |
|
20 | 28 | _T_co = TypeVar("_T_co", covariant=True) |
21 | 29 |
|
22 | 30 |
|
| 31 | +# These "Just" types are equivalent to the `Just` type from the `optype` library, |
| 32 | +# apart from them not being `@runtime_checkable`. |
| 33 | +# - docs: https://github.com/jorenham/optype/blob/master/README.md#just |
| 34 | +# - code: https://github.com/jorenham/optype/blob/master/optype/_core/_just.py |
| 35 | +@final |
| 36 | +class JustInt(Protocol): |
| 37 | + @property |
| 38 | + def __class__(self, /) -> type[int]: ... |
| 39 | + @__class__.setter |
| 40 | + def __class__(self, value: type[int], /) -> None: ... # pyright: ignore[reportIncompatibleMethodOverride] |
| 41 | + |
| 42 | + |
| 43 | +@final |
| 44 | +class JustFloat(Protocol): |
| 45 | + @property |
| 46 | + def __class__(self, /) -> type[float]: ... |
| 47 | + @__class__.setter |
| 48 | + def __class__(self, value: type[float], /) -> None: ... # pyright: ignore[reportIncompatibleMethodOverride] |
| 49 | + |
| 50 | + |
| 51 | +@final |
| 52 | +class JustComplex(Protocol): |
| 53 | + @property |
| 54 | + def __class__(self, /) -> type[complex]: ... |
| 55 | + @__class__.setter |
| 56 | + def __class__(self, value: type[complex], /) -> None: ... # pyright: ignore[reportIncompatibleMethodOverride] |
| 57 | + |
| 58 | + |
| 59 | +# |
| 60 | + |
| 61 | + |
23 | 62 | class NestedSequence(Protocol[_T_co]): |
24 | 63 | def __getitem__(self, key: int, /) -> _T_co | NestedSequence[_T_co]: ... |
25 | 64 | def __len__(self, /) -> int: ... |
@@ -78,6 +117,9 @@ def shape(self, /) -> tuple[_T_co, ...]: ... |
78 | 117 | "Device", |
79 | 118 | "HasShape", |
80 | 119 | "Namespace", |
| 120 | + "JustInt", |
| 121 | + "JustFloat", |
| 122 | + "JustComplex", |
81 | 123 | "NestedSequence", |
82 | 124 | "SupportsArrayNamespace", |
83 | 125 | "SupportsBufferProtocol", |
|
0 commit comments