dycw-utilities 0.122.1__py3-none-any.whl → 0.123.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dycw-utilities
3
- Version: 0.122.1
3
+ Version: 0.123.0
4
4
  Author-email: Derek Wan <d.wan@icloud.com>
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.12
@@ -1,7 +1,7 @@
1
- utilities/__init__.py,sha256=HQ1CqsUZ8X8-X0sFT3wvjjj0NMYqAnzvjRBDmvWB2xU,60
1
+ utilities/__init__.py,sha256=AxdGMrtAz54a0Yk125XZ1e--h0FOtLVgpyniB0rxFGA,60
2
2
  utilities/altair.py,sha256=Gpja-flOo-Db0PIPJLJsgzAlXWoKUjPU1qY-DQ829ek,9156
3
3
  utilities/astor.py,sha256=xuDUkjq0-b6fhtwjhbnebzbqQZAjMSHR1IIS5uOodVg,777
4
- utilities/asyncio.py,sha256=cjXpSezv95ZG3t-D9sXLOn6BGBj7w-Wf4udvE5gU4vU,23508
4
+ utilities/asyncio.py,sha256=PJR4WxQ4C5AlTyRcEd0_n2ZaIl37k3AirLBUytZ4Xcg,23267
5
5
  utilities/atomicwrites.py,sha256=geFjn9Pwn-tTrtoGjDDxWli9NqbYfy3gGL6ZBctiqSo,5393
6
6
  utilities/atools.py,sha256=IYMuFSFGSKyuQmqD6v5IUtDlz8PPw0Sr87Cub_gRU3M,1168
7
7
  utilities/cachetools.py,sha256=C1zqOg7BYz0IfQFK8e3qaDDgEZxDpo47F15RTfJM37Q,2910
@@ -88,7 +88,7 @@ utilities/warnings.py,sha256=un1LvHv70PU-LLv8RxPVmugTzDJkkGXRMZTE2-fTQHw,1771
88
88
  utilities/whenever.py,sha256=jS31ZAY5OMxFxLja_Yo5Fidi87Pd-GoVZ7Vi_teqVDA,16743
89
89
  utilities/zipfile.py,sha256=24lQc9ATcJxHXBPc_tBDiJk48pWyRrlxO2fIsFxU0A8,699
90
90
  utilities/zoneinfo.py,sha256=-5j7IQ9nb7gR43rdgA7ms05im-XuqhAk9EJnQBXxCoQ,1874
91
- dycw_utilities-0.122.1.dist-info/METADATA,sha256=9QN9Ulm7O-TsU1Zg2xrl5ylNadZMkHMp9ktRVFxpFwQ,12943
92
- dycw_utilities-0.122.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
93
- dycw_utilities-0.122.1.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
94
- dycw_utilities-0.122.1.dist-info/RECORD,,
91
+ dycw_utilities-0.123.0.dist-info/METADATA,sha256=pcPzAE2-DZzAYxtEr2fvJS3yPFJnQ942lzEuFcXfr-E,12943
92
+ dycw_utilities-0.123.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
93
+ dycw_utilities-0.123.0.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
94
+ dycw_utilities-0.123.0.dist-info/RECORD,,
utilities/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.122.1"
3
+ __version__ = "0.123.0"
utilities/asyncio.py CHANGED
@@ -87,7 +87,6 @@ class EnhancedTaskGroup(TaskGroup):
87
87
  _timeout: Duration | None
88
88
  _error: type[Exception]
89
89
  _stack: AsyncExitStack
90
- _stack_entered: bool
91
90
  _timeout_cm: _AsyncGeneratorContextManager[None] | None
92
91
 
93
92
  @override
@@ -103,7 +102,6 @@ class EnhancedTaskGroup(TaskGroup):
103
102
  self._timeout = timeout
104
103
  self._error = error
105
104
  self._stack = AsyncExitStack()
106
- self._stack_entered = False # TOOD: no need
107
105
  self._timeout_cm = None
108
106
 
109
107
  @override
@@ -136,8 +134,10 @@ class EnhancedTaskGroup(TaskGroup):
136
134
  coroutine = self._wrap_with_timeout(coroutine)
137
135
  return super().create_task(coroutine, name=name, context=context)
138
136
 
139
- async def enter_async_context(self, cm: AbstractAsyncContextManager[_T], /) -> _T:
140
- return await self._stack.enter_async_context(cm)
137
+ def create_task_context(self, cm: AbstractAsyncContextManager[_T], /) -> Task[_T]:
138
+ """Have the TaskGroup start an asynchronous context manager."""
139
+ _ = self._stack.push_async_callback(cm.__aexit__, None, None, None)
140
+ return self.create_task(cm.__aenter__())
141
141
 
142
142
  async def _wrap_with_semaphore(
143
143
  self, semaphore: Semaphore, coroutine: _CoroutineLike[_T], /
@@ -178,18 +178,12 @@ class InfiniteLooper(ABC, Generic[THashable]):
178
178
 
179
179
  async def __aenter__(self) -> Self:
180
180
  """Context manager entry."""
181
- if (self._task is None) and (self._depth == 0):
182
- _ = await self._stack.__aenter__()
181
+ if self._depth == 0:
183
182
  self._task = create_task(self._run_looper())
184
183
  if self._await_upon_aenter:
185
184
  with suppress(CancelledError):
186
185
  await self._task
187
- elif (self._task is not None) and (self._depth >= 1):
188
- ...
189
- else:
190
- raise ImpossibleCaseError( # pragma: no cover
191
- case=[f"{self._task=}", f"{self._depth=}"]
192
- )
186
+ _ = await self._stack.__aenter__()
193
187
  self._depth += 1
194
188
  return self
195
189
 
@@ -201,18 +195,16 @@ class InfiniteLooper(ABC, Generic[THashable]):
201
195
  ) -> None:
202
196
  """Context manager exit."""
203
197
  _ = (exc_type, exc_value, traceback)
204
- if (self._task is None) or (self._depth == 0):
205
- raise ImpossibleCaseError( # pragma: no cover
206
- case=[f"{self._task=}", f"{self._depth=}"]
207
- )
208
- self._depth -= 1
209
- if self._depth == 0:
210
- _ = await self._stack.__aexit__(exc_type, exc_value, traceback)
198
+ self._depth = max(self._depth - 1, 0)
199
+ if (self._depth == 0) and (self._task is not None):
211
200
  with suppress(CancelledError):
212
201
  await self._task
213
202
  self._task = None
214
- with suppress(Exception):
203
+ try:
215
204
  await self._teardown()
205
+ except Exception as error: # noqa: BLE001
206
+ self._error_upon_teardown(error)
207
+ _ = await self._stack.__aexit__(exc_type, exc_value, traceback)
216
208
 
217
209
  async def stop(self) -> None:
218
210
  """Stop the service."""