python-utils 3.8.2__py2.py3-none-any.whl → 3.9.1__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
python_utils/__about__.py CHANGED
@@ -1,3 +1,15 @@
1
+ """
2
+ This module contains metadata about the `python-utils` package.
3
+
4
+ Attributes:
5
+ __package_name__ (str): The name of the package.
6
+ __author__ (str): The author of the package.
7
+ __author_email__ (str): The email of the author.
8
+ __description__ (str): A brief description of the package.
9
+ __url__ (str): The URL of the package's repository.
10
+ __version__ (str): The current version of the package.
11
+ """
12
+
1
13
  __package_name__: str = 'python-utils'
2
14
  __author__: str = 'Rick van Hattem'
3
15
  __author_email__: str = 'Wolph@wol.ph'
@@ -7,4 +19,4 @@ __description__: str = (
7
19
  )
8
20
  __url__: str = 'https://github.com/WoLpH/python-utils'
9
21
  # Omit type info due to automatic versioning script
10
- __version__ = '3.8.2'
22
+ __version__ = '3.9.1'
python_utils/__init__.py CHANGED
@@ -1,6 +1,56 @@
1
+ """
2
+ This module initializes the `python_utils` package by importing various
3
+ submodules and functions.
4
+
5
+ Submodules:
6
+ aio
7
+ converters
8
+ decorators
9
+ formatters
10
+ generators
11
+ import_
12
+ logger
13
+ terminal
14
+ time
15
+ types
16
+
17
+ Functions:
18
+ acount
19
+ remap
20
+ scale_1024
21
+ to_float
22
+ to_int
23
+ to_str
24
+ to_unicode
25
+ listify
26
+ set_attributes
27
+ raise_exception
28
+ reraise
29
+ camel_to_underscore
30
+ timesince
31
+ abatcher
32
+ batcher
33
+ import_global
34
+ get_terminal_size
35
+ aio_generator_timeout_detector
36
+ aio_generator_timeout_detector_decorator
37
+ aio_timeout_generator
38
+ delta_to_seconds
39
+ delta_to_seconds_or_none
40
+ format_time
41
+ timedelta_to_seconds
42
+ timeout_generator
43
+
44
+ Classes:
45
+ CastedDict
46
+ LazyCastedDict
47
+ UniqueList
48
+ Logged
49
+ LoggerBase
50
+ """
51
+
1
52
  from . import (
2
53
  aio,
3
- compat,
4
54
  converters,
5
55
  decorators,
6
56
  formatters,
@@ -33,45 +83,44 @@ from .time import (
33
83
  )
34
84
 
35
85
  __all__ = [
86
+ 'CastedDict',
87
+ 'LazyCastedDict',
88
+ 'Logged',
89
+ 'LoggerBase',
90
+ 'UniqueList',
91
+ 'abatcher',
92
+ 'acount',
36
93
  'aio',
37
- 'generators',
38
- 'compat',
94
+ 'aio_generator_timeout_detector',
95
+ 'aio_generator_timeout_detector_decorator',
96
+ 'aio_timeout_generator',
97
+ 'batcher',
98
+ 'camel_to_underscore',
39
99
  'converters',
40
100
  'decorators',
101
+ 'delta_to_seconds',
102
+ 'delta_to_seconds_or_none',
103
+ 'format_time',
41
104
  'formatters',
105
+ 'generators',
106
+ 'get_terminal_size',
42
107
  'import_',
108
+ 'import_global',
109
+ 'listify',
43
110
  'logger',
44
- 'terminal',
45
- 'time',
46
- 'types',
47
- 'to_int',
48
- 'to_float',
49
- 'to_unicode',
50
- 'to_str',
51
- 'scale_1024',
111
+ 'raise_exception',
52
112
  'remap',
113
+ 'reraise',
114
+ 'scale_1024',
53
115
  'set_attributes',
54
- 'listify',
55
- 'camel_to_underscore',
56
- 'timesince',
57
- 'import_global',
58
- 'get_terminal_size',
116
+ 'terminal',
117
+ 'time',
59
118
  'timedelta_to_seconds',
60
- 'format_time',
61
119
  'timeout_generator',
62
- 'acount',
63
- 'abatcher',
64
- 'batcher',
65
- 'aio_timeout_generator',
66
- 'aio_generator_timeout_detector_decorator',
67
- 'aio_generator_timeout_detector',
68
- 'delta_to_seconds',
69
- 'delta_to_seconds_or_none',
70
- 'reraise',
71
- 'raise_exception',
72
- 'Logged',
73
- 'LoggerBase',
74
- 'CastedDict',
75
- 'LazyCastedDict',
76
- 'UniqueList',
120
+ 'timesince',
121
+ 'to_float',
122
+ 'to_int',
123
+ 'to_str',
124
+ 'to_unicode',
125
+ 'types',
77
126
  ]
python_utils/aio.py CHANGED
@@ -1,14 +1,15 @@
1
- '''
2
- Asyncio equivalents to regular Python functions.
1
+ """Asyncio equivalents to regular Python functions."""
3
2
 
4
- '''
5
3
  import asyncio
6
4
  import itertools
5
+ import typing
7
6
 
8
7
  from . import types
9
8
 
10
9
  _N = types.TypeVar('_N', int, float)
11
10
  _T = types.TypeVar('_T')
11
+ _K = types.TypeVar('_K')
12
+ _V = types.TypeVar('_V')
12
13
 
13
14
 
14
15
  async def acount(
@@ -17,7 +18,7 @@ async def acount(
17
18
  delay: float = 0,
18
19
  stop: types.Optional[_N] = None,
19
20
  ) -> types.AsyncIterator[_N]:
20
- '''Asyncio version of itertools.count()'''
21
+ """Asyncio version of itertools.count()."""
21
22
  for item in itertools.count(start, step): # pragma: no branch
22
23
  if stop is not None and item >= stop:
23
24
  break
@@ -26,20 +27,52 @@ async def acount(
26
27
  await asyncio.sleep(delay)
27
28
 
28
29
 
30
+ @typing.overload
29
31
  async def acontainer(
30
32
  iterable: types.Union[
31
33
  types.AsyncIterable[_T],
32
34
  types.Callable[..., types.AsyncIterable[_T]],
33
35
  ],
34
- container: types.Callable[[types.Iterable[_T]], types.Iterable[_T]] = list,
35
- ) -> types.Iterable[_T]:
36
- '''
37
- Asyncio version of list()/set()/tuple()/etc() using an async for loop
36
+ container: types.Type[types.Tuple[_T, ...]],
37
+ ) -> types.Tuple[_T, ...]: ...
38
+
39
+
40
+ @typing.overload
41
+ async def acontainer(
42
+ iterable: types.Union[
43
+ types.AsyncIterable[_T],
44
+ types.Callable[..., types.AsyncIterable[_T]],
45
+ ],
46
+ container: types.Type[types.List[_T]] = list,
47
+ ) -> types.List[_T]: ...
48
+
49
+
50
+ @typing.overload
51
+ async def acontainer(
52
+ iterable: types.Union[
53
+ types.AsyncIterable[_T],
54
+ types.Callable[..., types.AsyncIterable[_T]],
55
+ ],
56
+ container: types.Type[types.Set[_T]],
57
+ ) -> types.Set[_T]: ...
58
+
59
+
60
+ async def acontainer(
61
+ iterable: types.Union[
62
+ types.AsyncIterable[_T],
63
+ types.Callable[..., types.AsyncIterable[_T]],
64
+ ],
65
+ container: types.Callable[
66
+ [types.Iterable[_T]], types.Collection[_T]
67
+ ] = list,
68
+ ) -> types.Collection[_T]:
69
+ """
70
+ Asyncio version of list()/set()/tuple()/etc() using an async for loop.
38
71
 
39
72
  So instead of doing `[item async for item in iterable]` you can do
40
73
  `await acontainer(iterable)`.
41
74
 
42
- '''
75
+ """
43
76
  iterable_: types.AsyncIterable[_T]
44
77
  if callable(iterable):
45
78
  iterable_ = iterable()
@@ -52,3 +85,33 @@ async def acontainer(
52
85
  items.append(item)
53
86
 
54
87
  return container(items)
88
+
89
+
90
+ async def adict(
91
+ iterable: types.Union[
92
+ types.AsyncIterable[types.Tuple[_K, _V]],
93
+ types.Callable[..., types.AsyncIterable[types.Tuple[_K, _V]]],
94
+ ],
95
+ container: types.Callable[
96
+ [types.Iterable[types.Tuple[_K, _V]]], types.Mapping[_K, _V]
97
+ ] = dict,
98
+ ) -> types.Mapping[_K, _V]:
99
+ """
100
+ Asyncio version of dict() using an async for loop.
101
+
102
+ So instead of doing `{key: value async for key, value in iterable}` you
103
+ can do `await adict(iterable)`.
104
+
105
+ """
106
+ iterable_: types.AsyncIterable[types.Tuple[_K, _V]]
107
+ if callable(iterable):
108
+ iterable_ = iterable()
109
+ else:
110
+ iterable_ = iterable
111
+
112
+ item: types.Tuple[_K, _V]
113
+ items: types.List[types.Tuple[_K, _V]] = []
114
+ async for item in iterable_: # pragma: no branch
115
+ items.append(item)
116
+
117
+ return container(items)