Skip to content

Commit 7ff507f

Browse files
feedback
1 parent a82de37 commit 7ff507f

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

manim/utils/iterables.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def all_elements_are_instances(iterable: Iterable[object], Class: type[object])
8787

8888

8989
def batch_by_property(
90-
items: Sequence[T], property_func: Callable[[T], U]
90+
items: Iterable[T], property_func: Callable[[T], U]
9191
) -> list[tuple[list[T], U]]:
9292
"""Takes in a Sequence, and returns a list of tuples, (batch, prop)
9393
such that all items in a batch have the same output when
@@ -174,7 +174,7 @@ def listify(obj: Iterable[T]) -> list[T]: ...
174174
def listify(obj: T) -> list[T]: ...
175175

176176

177-
def listify(obj):
177+
def listify(obj: str | Iterable[T] | T) -> list[str] | list[T]:
178178
"""Converts obj to a list intelligently.
179179
180180
Examples
@@ -190,15 +190,15 @@ def listify(obj):
190190
"""
191191
if isinstance(obj, str):
192192
return [obj]
193-
try:
193+
if isinstance(obj, Iterable):
194194
return list(obj)
195-
except TypeError:
195+
else:
196196
return [obj]
197197

198198

199199
def make_even(
200200
iterable_1: Iterable[T], iterable_2: Iterable[U]
201-
) -> tuple[list[T | U], list[T | U]]:
201+
) -> tuple[list[T], list[U]]:
202202
"""Extends the shorter of the two iterables with duplicate values until its
203203
length is equal to the longer iterable (favours earlier elements).
204204
@@ -228,7 +228,7 @@ def make_even(
228228

229229
def make_even_by_cycling(
230230
iterable_1: Collection[T], iterable_2: Collection[U]
231-
) -> tuple[list[T | U], list[T | U]]:
231+
) -> tuple[list[T], list[U]]:
232232
"""Extends the shorter of the two iterables with duplicate values until its
233233
length is equal to the longer iterable (cycles over shorter iterable).
234234
@@ -269,7 +269,7 @@ def remove_list_redundancies(lst: Reversible[H]) -> list[H]:
269269
return reversed_result
270270

271271

272-
def remove_nones(sequence: Iterable) -> list:
272+
def remove_nones(sequence: Iterable[T | None]) -> list[T]:
273273
"""Removes elements where bool(x) evaluates to False.
274274
275275
Examples
@@ -422,7 +422,7 @@ def tuplify(obj: Iterable[T]) -> tuple[T]: ...
422422
def tuplify(obj: T) -> tuple[T]: ...
423423

424424

425-
def tuplify(obj):
425+
def tuplify(obj: str | Iterable[T] | T) -> tuple[str] | tuple[T]:
426426
"""Converts obj to a tuple intelligently.
427427
428428
Examples
@@ -438,9 +438,9 @@ def tuplify(obj):
438438
"""
439439
if isinstance(obj, str):
440440
return (obj,)
441-
try:
441+
if isinstance(obj, Iterable):
442442
return tuple(obj)
443-
except TypeError:
443+
else:
444444
return (obj,)
445445

446446

0 commit comments

Comments
 (0)