Coverage for src/toolbox_python/collection_types.py: 100%
27 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-06 07:32 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-06 07:32 +0000
1# ============================================================================ #
2# #
3# Title : Collection types #
4# Purpose : Defines various type aliases for common collection types. #
5# #
6# ============================================================================ #
9# ---------------------------------------------------------------------------- #
10# #
11# Setup ####
12# #
13# ---------------------------------------------------------------------------- #
16## --------------------------------------------------------------------------- #
17## Imports ####
18## --------------------------------------------------------------------------- #
21# ## Python StdLib Imports ----
22from typing import Any, Literal, Union
25## --------------------------------------------------------------------------- #
26## Exports ####
27## --------------------------------------------------------------------------- #
30__all__: list[str] = [
31 "any_collection",
32 "any_list",
33 "any_list_tuple",
34 "any_set",
35 "any_tuple",
36 "collection",
37 "dict_any",
38 "dict_str_int",
39 "int_list",
40 "int_tuple",
41 "iterable",
42 "log_levels",
43 "scalar",
44 "str_collection",
45 "str_dict",
46 "str_list",
47 "str_list_tuple",
48 "str_set",
49 "str_tuple",
50]
53## --------------------------------------------------------------------------- #
54## Types ####
55## --------------------------------------------------------------------------- #
58str_list = list[str]
59str_tuple = tuple[str, ...]
60str_set = set[str]
61str_dict = dict[str, str]
62str_list_tuple = Union[str_list, str_tuple]
63int_list = list[int]
64int_tuple = tuple[int, ...]
65any_list = list[Any]
66any_tuple = tuple[Any, ...]
67any_set = set[Any]
68any_list_tuple = Union[any_list, any_tuple]
69collection = Union[any_list, any_tuple, any_set]
70str_collection = Union[str_list, str_tuple, str_set]
71any_collection = Union[any_list, any_tuple, any_set]
72scalar = Union[str, int, float, bool]
73iterable = Union[list, tuple, set, dict]
76dict_any = dict[
77 Union[str, int],
78 Union[str, int, float, list, tuple, dict],
79]
80"""
81!!! note "Summary"
82 To streamline other functions, this `type` alias is created for a `Dict` containing certain types.
83!!! abstract "Details"
84 The structure of the `type` is as follows:
85 ```{.py .python linenums="1" title="Type structure"}
86 dict_any = Dict[
87 Union[str, int],
88 Union[str, int, float, list, tuple, dict],
89 ]
90 ```
91"""
94dict_str_int = dict[
95 Union[str, int],
96 Union[str, int],
97]
98"""
99!!! note "Summary"
100 To streamline other functions, this `type` alias is created for a `Dict` containing certain types.
101!!! abstract "Details"
102 The structure of the `type` is as follows:
103 ```{.py .python linenums="1" title="Type structure"}
104 dict_str_int = Dict[
105 Union[str, int],
106 Union[str, int],
107 ]
108 ```
109"""
112dict_str_any = dict[str, Any]
113dict_str_str = dict[str, str]
114dict_int_str = dict[int, str]
117log_levels = Literal["debug", "info", "warning", "error", "critical"]
118"""
119!!! note "Summary"
120 To streamline other functions, this `type` alias is created for all of the `log` levels available.
121!!! abstract "Details"
122 The structure of the `type` is as follows:
123 ```{.py .python linenums="1" title="Type structure"}
124 Literal["debug", "info", "warning", "error", "critical"]
125 ```
126"""