mwchase icon

Somewhat redacted fake hkt code

mwchase | PRO | 11/22/23 11:58:05 PM UTC | 0 ⭐ | 2320 👁️ | Never ⏰ | []
Python |

2.24 KB

|

None

|

0 👍

/

0 👎

"""Map from Type1[T] to Type2[T], where T is specific to the key."""
 
from __future__ import annotations
 
import typing
 
import pyrsistent
 
_T = typing.TypeVar("_T")
_K = typing.TypeVar("_K")
_V = typing.TypeVar("_V")
 
_TCallable = typing.TypeVar("_TCallable", bound=typing.Callable[..., object])
_TCallable_co = typing.TypeVar(
    "_TCallable_co", bound=typing.Callable[..., object], covariant=True
)
 
 
class Magma(typing.Protocol[_TCallable_co]):
    """Helper protocol for combining two values in a DependentMapping."""
 
    def __call__(
        self: Magma[typing.Callable[..., _V]], __lhs: _V, __rhs: _V
    ) -> _V:
        """Combine stored values."""
 
 
class DependentMapping(typing.Protocol[_TCallable]):
    """Perform type manipulations so advanced, Mypy doesn't allow them."""
 
    # Various other methods redacted for space
 
    def __iter__(
        self: DependentMapping[typing.Callable[[_K], _V]]
    ) -> typing.Iterator[_K]:
        """Iterate over the keys in the mapping."""
 
    def items(
        self: DependentMapping[typing.Callable[[_K], _V]]
    ) -> typing.ItemsView[_K, _V]:
        """Return an iterable of the key-value pairs stored in the mapping."""
 
    def iteritems(
        self: DependentMapping[typing.Callable[[_K], _V]]
    ) -> typing.Iterable[tuple[_K, _V]]:
        """Return an iterable of the key-value pairs stored in the mapping."""
 
    def iterkeys(
        self: DependentMapping[typing.Callable[[_K], _V]]
    ) -> typing.Iterable[_K]:
        """Return an iterable of the keys stored in the mapping."""
 
    def itervalues(
        self: DependentMapping[typing.Callable[[_K], _V]]
    ) -> typing.Iterable[_V]:
        """Return an iterable of the values stored in the mapping."""
 
    def keys(
        self: DependentMapping[typing.Callable[[_K], _V]]
    ) -> typing.KeysView[_K]:
        """Return an iterable of the keys stored in the mapping."""
 
    # Methods redacted for space
 
    def values(
        self: DependentMapping[typing.Callable[[_K], _V]]
    ) -> typing.ValuesView[_V]:
        """Return an iterable of the values stored in the mapping."""
 
 
_AnyMap = DependentMapping[typing.Any]
MAPPING: _AnyMap = typing.cast("_AnyMap", pyrsistent.pmap())

Comments