muutils.kappa
anonymous getitem class
util for constructing a class which has a getitem method which just calls a function
a lambda
is an anonymous function: kappa is the letter before lambda in the greek alphabet,
hence the name of this class
1"""anonymous getitem class 2 3util for constructing a class which has a getitem method which just calls a function 4 5a `lambda` is an anonymous function: kappa is the letter before lambda in the greek alphabet, 6hence the name of this class""" 7 8from __future__ import annotations 9 10from typing import Callable, Mapping, TypeVar 11 12_kappa_K = TypeVar("_kappa_K") 13_kappa_V = TypeVar("_kappa_V") 14 15# get the docstring of this file 16_BASE_DOC: str = ( 17 __doc__ 18 + """ 19 20source function docstring: 21==============================\n 22""" 23) 24 25 26class Kappa(Mapping[_kappa_K, _kappa_V]): 27 def __init__(self, func_getitem: Callable[[_kappa_K], _kappa_V]) -> None: 28 self.func_getitem = func_getitem 29 self.doc = _BASE_DOC + str( 30 getattr( 31 func_getitem, "__doc__", "<no docstring provided for source function>" 32 ) 33 ) 34 35 def __getitem__(self, x) -> _kappa_V: 36 return self.func_getitem(x) 37 38 def __iter__(self): 39 raise NotImplementedError( 40 "This method is not implemented for Kappa, we don't know the valid inputs" 41 ) 42 43 def __len__(self): 44 raise NotImplementedError( 45 "This method is not implemented for Kappa, no idea how many valid inputs there are" 46 )
class
Kappa(typing.Mapping[~_kappa_K, ~_kappa_V]):
27class Kappa(Mapping[_kappa_K, _kappa_V]): 28 def __init__(self, func_getitem: Callable[[_kappa_K], _kappa_V]) -> None: 29 self.func_getitem = func_getitem 30 self.doc = _BASE_DOC + str( 31 getattr( 32 func_getitem, "__doc__", "<no docstring provided for source function>" 33 ) 34 ) 35 36 def __getitem__(self, x) -> _kappa_V: 37 return self.func_getitem(x) 38 39 def __iter__(self): 40 raise NotImplementedError( 41 "This method is not implemented for Kappa, we don't know the valid inputs" 42 ) 43 44 def __len__(self): 45 raise NotImplementedError( 46 "This method is not implemented for Kappa, no idea how many valid inputs there are" 47 )
A Mapping is a generic container for associating key/value pairs.
This class provides concrete generic implementations of all methods except for __getitem__, __iter__, and __len__.
Inherited Members
- collections.abc.Mapping
- get
- keys
- items
- values