Skip to content

Commit abdcc29

Browse files
committed
(aesthetic) I really don't want to write my own formatter...
1 parent 057a1ce commit abdcc29

File tree

9 files changed

+53
-43
lines changed

9 files changed

+53
-43
lines changed

src/async_utils/__init__.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,36 @@
2020
# - update `_misc._ensure_annotations.py` before extending this version.
2121
# - ensure `task_cache.__WrappedSignature` still works
2222
if (_vi.major, _vi.minor) > (3, 14):
23-
msg: str = """This library is not tested for use on python versions above 3.14
24-
This library relies on a few internal details that are not safe to rely upon
25-
without checking this consistently.
26-
"""
23+
msg: str = (
24+
"This library is not tested for use on python versions above 3.14."
25+
"\nThis library relies on a few internal details that are not "
26+
"safe to rely upon without checking for changes to internals "
27+
"consistently."
28+
)
2729
if os.getenv("ASYNC_UTILS_UNCHECKED_PY_VER", ""):
2830
import logging
2931

30-
msg += """\n\nThis is not neccessarily broken, but if you encounter an
31-
issue with it, please be aware that the library has not actively
32-
chosen to support the python version you have opted into using this on
33-
*yet*. If you encounter an issue with it, please do still report it.
34-
"""
32+
msg += (
33+
"\n\nThis is not neccessarily broken, but if you encounter an "
34+
"issue with it, please be aware that the library has not actively "
35+
"chosen to support the python version you have opted into using "
36+
"yet. If you encounter an issue with it, please still report it. "
37+
)
3538

3639
logging.getLogger(__name__).warning(msg)
3740
elif sys.version_info.releaselevel in {"alpha", "beta", "candidate"}:
3841
import logging
3942

40-
msg += """\nThanks for testing this (and a development version of python)
41-
prior to release!.\n"""
43+
msg += (
44+
"\nThanks for testing this (and a development version of python) "
45+
" prior to release!."
46+
)
4247
logging.getLogger(__name__).warning(msg)
4348
else:
44-
msg += """\nYou can change this error to a warning if you are sure it is
45-
safe and are willing to take the risk on yourself before I have verified
46-
it by setting the environment variable `ASYNC_UTILS_UNCHECKED_PY_VER`
47-
to a non-empty value.
48-
"""
49+
msg += (
50+
"\nYou can change this error to a warning if you are sure it "
51+
"safe and are willing to take the risk on yourself before I "
52+
"have verified it by setting the environment variable "
53+
"`ASYNC_UTILS_UNCHECKED_PY_VER` to a non-empty value."
54+
)
4955
raise RuntimeError(msg)

src/async_utils/_qs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __gt__(self, other: _contraT) -> bool: ...
4444
else:
4545

4646
class ExprWrapper:
47-
"""Future proof against runtime change preventing call expr in type statement."""
47+
"""Wrapper since call expressions aren't allowed in type statements."""
4848

4949
def __class_getitem__(cls, key: None) -> t.Any:
5050
import typing

src/async_utils/corofunc_cache.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __call__[**P, R](self, c: CoroLike[P, R], /) -> CoroFunc[P, R]: ...
5050
def f__call__[**P, R](self, c: CoroLike[P, R], /) -> CoroFunc[P, R]: ... # noqa: ANN001
5151

5252
class ExprWrapper:
53-
"""Future proof against runtime change preventing call expr in type statement."""
53+
"""Wrapper since call expressions aren't allowed in type statements."""
5454

5555
def __class_getitem__(cls, key: None) -> t.Any:
5656
return type(
@@ -83,7 +83,9 @@ def corocache(
8383
restrictive.
8484
8585
Note: This by default uses the args and kwargs of the original coroutine
86-
function as a cache key. This includes instances (self) when wrapping methods.
86+
function as a cache key.
87+
This includes instances (self) when wrapping methods.
88+
8789
Consider not wrapping instance methods, but what those methods call when
8890
feasible in cases where this may matter, or using a cache transform.
8991
@@ -92,7 +94,8 @@ def corocache(
9294
Parameters
9395
----------
9496
ttl: float | None
95-
The time to live in seconds for cached results. Defaults to None (forever)
97+
The time to live in seconds for cached results.
98+
Defaults to None (forever)
9699
cache_transform: CacheTransformer | None
97100
An optional callable that transforms args and kwargs used
98101
as a cache key.
@@ -158,7 +161,8 @@ def lrucorocache(
158161
restrictive.
159162
160163
Note: This by default uses the args and kwargs of the original coroutine
161-
function as a cache key. This includes instances (self) when wrapping methods.
164+
function as a cache key.
165+
This includes instances (self) when wrapping methods.
162166
Consider not wrapping instance methods, but what those methods call when
163167
feasible in cases where this may matter, or using a cache transform.
164168
@@ -169,7 +173,8 @@ def lrucorocache(
169173
Parameters
170174
----------
171175
ttl: float | None
172-
The time to live in seconds for cached results. Defaults to None (forever)
176+
The time to live in seconds for cached results.
177+
Defaults to None (forever)
173178
maxsize: int
174179
The maximum number of items to retain no matter if they have reached
175180
expiration by ttl or not.

src/async_utils/gen_transform.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ async def gen() -> AsyncGenerator[Y]:
135135
lazy_ev.set()
136136
while q:
137137
yield (await q.async_get())
138-
# ensure errors in the generator propogate *after* the last values yielded
138+
# ensure errors propogate *after* the last values yielded
139139
await bg_task
140140

141141
return gen(), cancel_fut
@@ -156,11 +156,11 @@ def sync_to_async_gen[**P, Y](
156156
are not appropriate for this function. similarly, generator return values
157157
are completely swallowed.
158158
159-
If your generator is actually a synchronous coroutine, that's super cool,
160-
but rewrite is as a native coroutine or use it directly then, you don't need
161-
what this function does.
159+
.. note:: If your generator is actually a synchronous coroutine,
160+
that's super cool, but rewrite is as a native coroutine or use it directly;
161+
you don't need what this function does.
162+
162163
163-
.. note::
164164
165165
Parameters
166166
----------
@@ -195,14 +195,12 @@ def sync_to_async_gen_noctx[**P, Y](
195195
are not appropriate for this function. similarly, generator return values
196196
are completely swallowed.
197197
198-
If your generator is actually a synchronous coroutine, that's super cool,
199-
but rewrite is as a native coroutine or use it directly then, you don't need
200-
what this function does.
198+
.. note:: If your generator is actually a synchronous coroutine,
199+
that's super cool, but rewrite is as a native coroutine or use it directly;
200+
you don't need what this function does.
201201
202202
This version does not forward exception context and is not a context manager.
203203
204-
.. note::
205-
206204
Parameters
207205
----------
208206
f:

src/async_utils/lockout.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ class FIFOLockout:
130130
async with ratelimiter, lockout:
131131
response = await some_request(route, **parameters)
132132
if response.code == 429:
133-
if reset_after := response.headers.get('X-Ratelimit-Reset-After')
133+
headers = response.headers
134+
if reset_after := headers.get('X-Ratelimit-Reset-After')
134135
lockout.lock_for(reset_after)
135136
"""
136137

src/async_utils/lru.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@
3232

3333

3434
class ProbableTOCTOUError(Exception):
35-
"""Raised for operations that should not be done to avoid a Time of check-time of use bug."""
35+
"""Time of check-time of use bugs."""
3636

3737

3838
class ContainsMisuse(ProbableTOCTOUError):
39-
"""Checking containment rather than just getting, setting, or using setdefault."""
39+
"""Checking cache value exists rather than handling non-existence."""
4040

4141

4242
class IterationMisuse(ProbableTOCTOUError):
43-
"""Iterating over a mutable container that can change simply because of time or other access."""
43+
"""Iterating over a mutable cache."""
4444

4545

4646
class LRU[K, V]:

src/async_utils/scheduler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ def __init__(self, granularity: float, /) -> None:
7878
self.__granularity: float = granularity
7979
self.__closed: bool = False
8080
self.__tasks: dict[CancellationToken, _Task[T]] = {}
81-
# PYUPGRADE: check: 3.15; relies on asyncio.Lock & Queues not eagerly binding to an event loop.
81+
# PYUPGRADE: check: 3.15;
82+
# relies on asyncio.Lock & Queues not eagerly binding to an event loop.
8283
self.__l = asyncio.Lock()
8384
self.__tqueue: asyncio.PriorityQueue[_Task[T]] = asyncio.PriorityQueue()
8485

src/async_utils/task_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __call__[**P, R](
5353
def f__call__[**P, R](self, c: TaskCoroFunc[P, R], /) -> TaskFunc[P, R]: ... # noqa: ANN001
5454

5555
class ExprWrapper:
56-
"""Future proof against runtime change preventing call expr in type statement."""
56+
"""Wrapper since call expressions aren't allowed in type statements."""
5757

5858
def __class_getitem__(cls, key: None) -> t.Any:
5959
return type(

src/async_utils/waterfall.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,8 @@ async def _dispatch_loop(self) -> None:
182182
# the result of that future is also not accurate in the typeshed.
183183
# as we dont rely on the type of the result, the below is annotated
184184
# to avoid spurious errors much as possible from inaccuracies.
185-
# See: https://github.com/mikeshardmind/async-utils/actions/runs/14119338111
186-
g: asyncio.Future[t.Any] = asyncio.gather(
187-
f, *tasks, return_exceptions=True
188-
)
185+
g: asyncio.Future[t.Any]
186+
g = asyncio.gather(f, *tasks, return_exceptions=True)
189187
try:
190188
await asyncio.wait_for(g, timeout=self.max_wait_finalize)
191189
except TimeoutError:
@@ -198,7 +196,8 @@ async def _dispatch_loop(self) -> None:
198196
async def _finalize(self) -> None:
199197
loop = self._event_loop
200198
assert loop is not None
201-
# WARNING: Do not allow an async context switch before the queue is drained
199+
# WARNING:
200+
# Do not allow an async context switch before the queue is drained
202201
# This can be changed to utilize queue.Shutdown in 3.13+
203202
# or when more of asyncio queues have been replaced here
204203
# as part of freethreading efforts.

0 commit comments

Comments
 (0)