Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/multidict/_abc.py: 96%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

47 statements  

1import abc 

2from collections.abc import Iterable, Mapping, MutableMapping 

3from typing import TYPE_CHECKING, Protocol, TypeVar, Union, overload 

4 

5if TYPE_CHECKING: 

6 from ._multidict_py import istr 

7else: 

8 istr = str 

9 

10_V = TypeVar("_V") 

11_V_co = TypeVar("_V_co", covariant=True) 

12_T = TypeVar("_T") 

13 

14 

15class SupportsKeys(Protocol[_V_co]): 

16 def keys(self) -> Iterable[str]: ... 

17 def __getitem__(self, key: str, /) -> _V_co: ... 

18 

19 

20class SupportsIKeys(Protocol[_V_co]): 

21 def keys(self) -> Iterable[istr]: ... 

22 def __getitem__(self, key: istr, /) -> _V_co: ... 

23 

24 

25MDArg = Union[SupportsKeys[_V], SupportsIKeys[_V], Iterable[tuple[str, _V]], None] 

26 

27 

28class MultiMapping(Mapping[str, _V_co]): 

29 @overload 

30 def getall(self, key: str) -> list[_V_co]: ... 

31 @overload 

32 def getall(self, key: str, default: _T) -> Union[list[_V_co], _T]: ... 

33 @abc.abstractmethod 

34 def getall(self, key: str, default: _T = ...) -> Union[list[_V_co], _T]: 

35 """Return all values for key.""" 

36 

37 @overload 

38 def getone(self, key: str) -> _V_co: ... 

39 @overload 

40 def getone(self, key: str, default: _T) -> Union[_V_co, _T]: ... 

41 @abc.abstractmethod 

42 def getone(self, key: str, default: _T = ...) -> Union[_V_co, _T]: 

43 """Return first value for key.""" 

44 

45 

46class MutableMultiMapping(MultiMapping[_V], MutableMapping[str, _V]): 

47 @abc.abstractmethod 

48 def add(self, key: str, value: _V) -> None: 

49 """Add value to list.""" 

50 

51 @abc.abstractmethod 

52 def extend(self, arg: MDArg[_V] = None, /, **kwargs: _V) -> None: 

53 """Add everything from arg and kwargs to the mapping.""" 

54 

55 @overload 

56 def popone(self, key: str) -> _V: ... 

57 @overload 

58 def popone(self, key: str, default: _T) -> Union[_V, _T]: ... 

59 @abc.abstractmethod 

60 def popone(self, key: str, default: _T = ...) -> Union[_V, _T]: 

61 """Remove specified key and return the corresponding value.""" 

62 

63 @overload 

64 def popall(self, key: str) -> list[_V]: ... 

65 @overload 

66 def popall(self, key: str, default: _T) -> Union[list[_V], _T]: ... 

67 @abc.abstractmethod 

68 def popall(self, key: str, default: _T = ...) -> Union[list[_V], _T]: 

69 """Remove all occurrences of key and return the list of corresponding values."""