Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/git/types.py: 76%

42 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2023-07-17 14:22 -0600

1# -*- coding: utf-8 -*- 

2# This module is part of GitPython and is released under 

3# the BSD License: http://www.opensource.org/licenses/bsd-license.php 

4# flake8: noqa 

5 

6import os 

7import sys 

8from typing import ( 

9 Dict, 

10 NoReturn, 

11 Sequence, 

12 Tuple, 

13 Union, 

14 Any, 

15 TYPE_CHECKING, 

16 TypeVar, 

17) # noqa: F401 

18 

19if sys.version_info[:2] >= (3, 8): 19 ↛ 28line 19 didn't jump to line 28, because the condition on line 19 was never false

20 from typing import ( 

21 Literal, 

22 SupportsIndex, 

23 TypedDict, 

24 Protocol, 

25 runtime_checkable, 

26 ) # noqa: F401 

27else: 

28 from typing_extensions import ( 

29 Literal, 

30 SupportsIndex, # noqa: F401 

31 TypedDict, 

32 Protocol, 

33 runtime_checkable, 

34 ) # noqa: F401 

35 

36# if sys.version_info[:2] >= (3, 10): 

37# from typing import TypeGuard # noqa: F401 

38# else: 

39# from typing_extensions import TypeGuard # noqa: F401 

40 

41 

42if sys.version_info[:2] < (3, 9): 42 ↛ 43line 42 didn't jump to line 43, because the condition on line 42 was never true

43 PathLike = Union[str, os.PathLike] 

44else: 

45 # os.PathLike only becomes subscriptable from Python 3.9 onwards 

46 PathLike = Union[str, os.PathLike[str]] 

47 

48if TYPE_CHECKING: 48 ↛ 49line 48 didn't jump to line 49, because the condition on line 48 was never true

49 from git.repo import Repo 

50 from git.objects import Commit, Tree, TagObject, Blob 

51 

52 # from git.refs import SymbolicReference 

53 

54TBD = Any 

55_T = TypeVar("_T") 

56 

57Tree_ish = Union["Commit", "Tree"] 

58Commit_ish = Union["Commit", "TagObject", "Blob", "Tree"] 

59Lit_commit_ish = Literal["commit", "tag", "blob", "tree"] 

60 

61# Config_levels --------------------------------------------------------- 

62 

63Lit_config_levels = Literal["system", "global", "user", "repository"] 

64 

65 

66# def is_config_level(inp: str) -> TypeGuard[Lit_config_levels]: 

67# # return inp in get_args(Lit_config_level) # only py >= 3.8 

68# return inp in ("system", "user", "global", "repository") 

69 

70 

71ConfigLevels_Tup = Tuple[Literal["system"], Literal["user"], Literal["global"], Literal["repository"]] 

72 

73# ----------------------------------------------------------------------------------- 

74 

75 

76def assert_never(inp: NoReturn, raise_error: bool = True, exc: Union[Exception, None] = None) -> None: 

77 """For use in exhaustive checking of literal or Enum in if/else chain. 

78 Should only be reached if all members not handled OR attempt to pass non-members through chain. 

79 

80 If all members handled, type is Empty. Otherwise, will cause mypy error. 

81 If non-members given, should cause mypy error at variable creation. 

82 

83 If raise_error is True, will also raise AssertionError or the Exception passed to exc. 

84 """ 

85 if raise_error: 

86 if exc is None: 

87 raise ValueError(f"An unhandled Literal ({inp}) in an if/else chain was found") 

88 else: 

89 raise exc 

90 

91 

92class Files_TD(TypedDict): 

93 insertions: int 

94 deletions: int 

95 lines: int 

96 

97 

98class Total_TD(TypedDict): 

99 insertions: int 

100 deletions: int 

101 lines: int 

102 files: int 

103 

104 

105class HSH_TD(TypedDict): 

106 total: Total_TD 

107 files: Dict[PathLike, Files_TD] 

108 

109 

110@runtime_checkable 

111class Has_Repo(Protocol): 

112 repo: "Repo" 

113 

114 

115@runtime_checkable 

116class Has_id_attribute(Protocol): 

117 _id_attribute_: str