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

10 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2025-12-09 01:06 +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_co = TypeVar("_T_co", covariant=True) 

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

10 

11 

12class SupportsWrite(Protocol[_T_contra]): 

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

14 

15 

16class SupportsReadAndReadline(Protocol[_T_co]): 

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

18 

19 @overload 

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

21 

22 @overload 

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

24 

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

26 

27 

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

29 # noinspection GrazieInspection 

30 """ 

31 可索引 

32 

33 .. versionchanged:: 0.2.0 

34 重命名 ``SupportsIndex`` 为 ``Indexed`` 

35 """ 

36 

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

38 

39 

40class MutableIndexed(Indexed[_T_contra, _T_co]): 

41 # noinspection GrazieInspection 

42 """ 

43 可变可索引 

44 

45 .. versionchanged:: 0.2.0 

46 重命名 ``SupportsWriteIndex`` 为 ``MutableIndexed`` 

47 """ 

48 

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

50 

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

52 

53 

54__all__ = ( 

55 "Indexed", 

56 "MutableIndexed", 

57 "SupportsReadAndReadline", 

58 "SupportsWrite", 

59)