Coverage for src/c41811/config/_protocols.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.15.0, created at 2026-07-04 11:16 +0000

1# cython: language_level = 3 # noqa: ERA001 

2 

3 

4from typing import Protocol 

5from typing import TypeVar 

6from typing import overload 

7 

8_T = TypeVar("_T") 

9_T_co = TypeVar("_T_co", covariant=True) 

10_T_contra = TypeVar("_T_contra", contravariant=True) 

11 

12 

13class SupportsWrite(Protocol[_T_contra]): 

14 def write(self, __s: _T_contra) -> object: ... 

15 

16 

17class SupportsReadAndReadline(Protocol[_T_co]): 

18 def read(self, __length: int = ...) -> _T_co: ... 

19 

20 @overload 

21 def readline(self) -> _T_co: ... 

22 

23 @overload 

24 def readline(self, __length: int) -> _T_co: ... 

25 

26 def readline(self, __length: int = ...) -> _T_co: ... 

27 

28 

29class Indexed(Protocol[_T_contra, _T_co]): 

30 # noinspection GrazieInspection 

31 """ 

32 可索引 

33 

34 .. versionchanged:: 0.2.0 

35 重命名 ``SupportsIndex`` 为 ``Indexed`` 

36 """ 

37 

38 def __getitem__(self, __index: _T_contra) -> _T_co: ... 

39 

40 

41class MutableIndexed(Protocol[_T_contra, _T]): 

42 # noinspection GrazieInspection 

43 """ 

44 可变可索引 

45 

46 .. versionchanged:: 0.2.0 

47 重命名 ``SupportsWriteIndex`` 为 ``MutableIndexed`` 

48 """ 

49 

50 def __getitem__(self, item: _T_contra) -> _T: ... 

51 

52 def __setitem__(self, __index: _T_contra, __value: _T) -> None: ... 

53 

54 def __delitem__(self, __index: _T_contra) -> None: ... 

55 

56 

57__all__ = ( 

58 "Indexed", 

59 "MutableIndexed", 

60 "SupportsReadAndReadline", 

61 "SupportsWrite", 

62)