Coverage for src/toolbox_python/collection_types.py: 100%

34 statements  

« prev     ^ index     » next       coverage.py v7.8.2, created at 2025-05-25 21:45 +0000

1# ============================================================================ # 

2# # 

3# Title : Collection types # 

4# Purpose : Defines various type aliases for common collection types. # 

5# # 

6# ============================================================================ # 

7 

8 

9# ---------------------------------------------------------------------------- # 

10# # 

11# Setup #### 

12# # 

13# ---------------------------------------------------------------------------- # 

14 

15 

16## --------------------------------------------------------------------------- # 

17## Imports #### 

18## --------------------------------------------------------------------------- # 

19 

20 

21# ## Python StdLib Imports ---- 

22from datetime import datetime 

23from typing import Any, Literal, Union 

24 

25 

26## --------------------------------------------------------------------------- # 

27## Exports #### 

28## --------------------------------------------------------------------------- # 

29 

30 

31__all__: list[str] = [ 

32 "any_collection", 

33 "any_list", 

34 "any_list_tuple", 

35 "any_set", 

36 "any_tuple", 

37 "collection", 

38 "dict_any", 

39 "dict_str_int", 

40 "int_list", 

41 "int_tuple", 

42 "iterable", 

43 "log_levels", 

44 "scalar", 

45 "str_collection", 

46 "str_dict", 

47 "str_list", 

48 "str_list_tuple", 

49 "str_set", 

50 "str_tuple", 

51] 

52 

53 

54## --------------------------------------------------------------------------- # 

55## Types #### 

56## --------------------------------------------------------------------------- # 

57 

58 

59### `str` collections ---- 

60str_list = list[str] 

61str_tuple = tuple[str, ...] 

62str_set = set[str] 

63str_list_tuple = Union[str_list, str_tuple] 

64 

65### `int` collections ---- 

66int_list = list[int] 

67int_tuple = tuple[int, ...] 

68int_set = set[int] 

69int_list_tuple = Union[int_list, int_tuple] 

70 

71### `datetime` collections ---- 

72datetime_list = list[datetime] 

73datetime_tuple = tuple[datetime, ...] 

74datetime_set = set[datetime] 

75datetime_list_tuple = Union[datetime_list, datetime_tuple] 

76 

77### `Any` collections ---- 

78any_list = list[Any] 

79any_tuple = tuple[Any, ...] 

80any_set = set[Any] 

81any_list_tuple = Union[any_list, any_tuple] 

82 

83### Generic collections ---- 

84collection = Union[any_list, any_tuple, any_set] 

85str_collection = Union[str_list, str_tuple, str_set] 

86any_collection = Union[any_list, any_tuple, any_set] 

87 

88### basic collections ---- 

89scalar = Union[str, int, float, bool] 

90iterable = Union[list, tuple, set, dict] 

91 

92### `dict` collections ---- 

93str_dict = dict[str, str] 

94dict_str_any = dict[str, Any] 

95dict_str_str = dict[str, str] 

96dict_int_str = dict[int, str] 

97 

98dict_any = dict[ 

99 Union[str, int], 

100 Union[str, int, float, list, tuple, dict], 

101] 

102""" 

103!!! note "Summary" 

104 To streamline other functions, this `type` alias is created for a `Dict` containing certain types. 

105!!! abstract "Details" 

106 The structure of the `type` is as follows: 

107 ```{.py .python linenums="1" title="Type structure"} 

108 dict_any = Dict[ 

109 Union[str, int], 

110 Union[str, int, float, list, tuple, dict], 

111 ] 

112 ``` 

113""" 

114 

115dict_str_int = dict[ 

116 Union[str, int], 

117 Union[str, int], 

118] 

119""" 

120!!! note "Summary" 

121 To streamline other functions, this `type` alias is created for a `Dict` containing certain types. 

122!!! abstract "Details" 

123 The structure of the `type` is as follows: 

124 ```{.py .python linenums="1" title="Type structure"} 

125 dict_str_int = Dict[ 

126 Union[str, int], 

127 Union[str, int], 

128 ] 

129 ``` 

130""" 

131 

132 

133log_levels = Literal["debug", "info", "warning", "error", "critical"] 

134""" 

135!!! note "Summary" 

136 To streamline other functions, this `type` alias is created for all of the `log` levels available. 

137!!! abstract "Details" 

138 The structure of the `type` is as follows: 

139 ```{.py .python linenums="1" title="Type structure"} 

140 Literal["debug", "info", "warning", "error", "critical"] 

141 ``` 

142"""