Skip to content

Commit fb554fd

Browse files
committed
♻️ remove as_chunks function
1 parent d0a094d commit fb554fd

File tree

3 files changed

+2
-68
lines changed

3 files changed

+2
-68
lines changed

CHANGELOG-V3.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ release.
2222
- `utils.warn_deprecated`
2323
- `utils.deprecated`
2424
- `utils.get` use `utils.find` instead
25+
- `utils.as_chunks` use `itertools.batched` on Python 3.12+ or your own implementation
26+
instead

discord/utils/__init__.py

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
"snowflake_time",
7777
"find",
7878
"get_or_fetch",
79-
"sleep_until ",
8079
"utcnow",
8180
"remove_markdown",
8281
"escape_markdown",
@@ -547,68 +546,3 @@ def raw_role_mentions(text: str) -> list[int]:
547546
A list of role IDs found in the string.
548547
"""
549548
return [int(x) for x in re.findall(r"<@&([0-9]+)>", text)]
550-
551-
552-
def _chunk(iterator: Iterator[T], max_size: int) -> Iterator[list[T]]:
553-
ret = []
554-
n = 0
555-
for item in iterator:
556-
ret.append(item)
557-
n += 1
558-
if n == max_size:
559-
yield ret
560-
ret = []
561-
n = 0
562-
if ret:
563-
yield ret
564-
565-
566-
async def _achunk(iterator: AsyncIterator[T], max_size: int) -> AsyncIterator[list[T]]:
567-
ret = []
568-
n = 0
569-
async for item in iterator:
570-
ret.append(item)
571-
n += 1
572-
if n == max_size:
573-
yield ret
574-
ret = []
575-
n = 0
576-
if ret:
577-
yield ret
578-
579-
580-
@overload
581-
def as_chunks(iterator: Iterator[T], max_size: int) -> Iterator[list[T]]: ...
582-
583-
584-
@overload
585-
def as_chunks(iterator: AsyncIterator[T], max_size: int) -> AsyncIterator[list[T]]: ...
586-
587-
588-
def as_chunks(iterator: _Iter[T], max_size: int) -> _Iter[list[T]]:
589-
"""A helper function that collects an iterator into chunks of a given size.
590-
591-
.. versionadded:: 2.0
592-
593-
.. warning::
594-
595-
The last chunk collected may not be as large as ``max_size``.
596-
597-
Parameters
598-
----------
599-
iterator: Union[:class:`collections.abc.Iterator`, :class:`collections.abc.AsyncIterator`]
600-
The iterator to chunk, can be sync or async.
601-
max_size: :class:`int`
602-
The maximum chunk size.
603-
604-
Returns
605-
-------
606-
Union[:class:`collections.abc.Iterator`, :class:`collections.abc.AsyncIterator`]
607-
A new iterator which yields chunks of a given size.
608-
"""
609-
if max_size <= 0:
610-
raise ValueError("Chunk sizes must be greater than 0.")
611-
612-
if isinstance(iterator, AsyncIterator):
613-
return _achunk(iterator, max_size)
614-
return _chunk(iterator, max_size)

docs/api/utils.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,3 @@ Utility Functions
3333
.. autofunction:: discord.utils.generate_snowflake
3434

3535
.. autofunction:: discord.utils.basic_autocomplete
36-
37-
.. autofunction:: discord.utils.as_chunks

0 commit comments

Comments
 (0)