Coverage for muutils/kappa.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-04-04 03:33 -0600

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 )