|
2 | 2 |
|
3 | 3 | from collections.abc import Mapping
|
4 | 4 | from types import ModuleType as Namespace
|
5 |
| -from typing import TYPE_CHECKING, Literal, Protocol, TypeAlias, TypedDict, TypeVar |
| 5 | +from typing import ( |
| 6 | + TYPE_CHECKING, |
| 7 | + Literal, |
| 8 | + Protocol, |
| 9 | + TypeAlias, |
| 10 | + TypedDict, |
| 11 | + TypeVar, |
| 12 | + final, |
| 13 | +) |
6 | 14 |
|
7 | 15 | if TYPE_CHECKING:
|
8 | 16 | from _typeshed import Incomplete
|
|
21 | 29 | _T_co = TypeVar("_T_co", covariant=True)
|
22 | 30 |
|
23 | 31 |
|
| 32 | +# These "Just" types are equivalent to the `Just` type from the `optype` library, |
| 33 | +# apart from them not being `@runtime_checkable`. |
| 34 | +# - docs: https://github.com/jorenham/optype/blob/master/README.md#just |
| 35 | +# - code: https://github.com/jorenham/optype/blob/master/optype/_core/_just.py |
| 36 | +@final |
| 37 | +class JustInt(Protocol): |
| 38 | + @property |
| 39 | + def __class__(self, /) -> type[int]: ... |
| 40 | + @__class__.setter |
| 41 | + def __class__(self, value: type[int], /) -> None: ... # pyright: ignore[reportIncompatibleMethodOverride] |
| 42 | + |
| 43 | + |
| 44 | +@final |
| 45 | +class JustFloat(Protocol): |
| 46 | + @property |
| 47 | + def __class__(self, /) -> type[float]: ... |
| 48 | + @__class__.setter |
| 49 | + def __class__(self, value: type[float], /) -> None: ... # pyright: ignore[reportIncompatibleMethodOverride] |
| 50 | + |
| 51 | + |
| 52 | +@final |
| 53 | +class JustComplex(Protocol): |
| 54 | + @property |
| 55 | + def __class__(self, /) -> type[complex]: ... |
| 56 | + @__class__.setter |
| 57 | + def __class__(self, value: type[complex], /) -> None: ... # pyright: ignore[reportIncompatibleMethodOverride] |
| 58 | + |
| 59 | + |
| 60 | +# |
| 61 | + |
| 62 | + |
24 | 63 | class NestedSequence(Protocol[_T_co]):
|
25 | 64 | def __getitem__(self, key: int, /) -> _T_co | NestedSequence[_T_co]: ...
|
26 | 65 | def __len__(self, /) -> int: ...
|
@@ -140,6 +179,9 @@ class DTypesAll(DTypesBool, DTypesNumeric):
|
140 | 179 | "Device",
|
141 | 180 | "HasShape",
|
142 | 181 | "Namespace",
|
| 182 | + "JustInt", |
| 183 | + "JustFloat", |
| 184 | + "JustComplex", |
143 | 185 | "NestedSequence",
|
144 | 186 | "SupportsArrayNamespace",
|
145 | 187 | "SupportsBufferProtocol",
|
|
0 commit comments