@@ -87,7 +87,7 @@ def all_elements_are_instances(iterable: Iterable[object], Class: type[object])
87
87
88
88
89
89
def batch_by_property (
90
- items : Sequence [T ], property_func : Callable [[T ], U ]
90
+ items : Iterable [T ], property_func : Callable [[T ], U ]
91
91
) -> list [tuple [list [T ], U ]]:
92
92
"""Takes in a Sequence, and returns a list of tuples, (batch, prop)
93
93
such that all items in a batch have the same output when
@@ -174,7 +174,7 @@ def listify(obj: Iterable[T]) -> list[T]: ...
174
174
def listify (obj : T ) -> list [T ]: ...
175
175
176
176
177
- def listify (obj ) :
177
+ def listify (obj : str | Iterable [ T ] | T ) -> list [ str ] | list [ T ] :
178
178
"""Converts obj to a list intelligently.
179
179
180
180
Examples
@@ -190,15 +190,15 @@ def listify(obj):
190
190
"""
191
191
if isinstance (obj , str ):
192
192
return [obj ]
193
- try :
193
+ if isinstance ( obj , Iterable ) :
194
194
return list (obj )
195
- except TypeError :
195
+ else :
196
196
return [obj ]
197
197
198
198
199
199
def make_even (
200
200
iterable_1 : Iterable [T ], iterable_2 : Iterable [U ]
201
- ) -> tuple [list [T | U ], list [T | U ]]:
201
+ ) -> tuple [list [T ], list [U ]]:
202
202
"""Extends the shorter of the two iterables with duplicate values until its
203
203
length is equal to the longer iterable (favours earlier elements).
204
204
@@ -228,7 +228,7 @@ def make_even(
228
228
229
229
def make_even_by_cycling (
230
230
iterable_1 : Collection [T ], iterable_2 : Collection [U ]
231
- ) -> tuple [list [T | U ], list [T | U ]]:
231
+ ) -> tuple [list [T ], list [U ]]:
232
232
"""Extends the shorter of the two iterables with duplicate values until its
233
233
length is equal to the longer iterable (cycles over shorter iterable).
234
234
@@ -269,7 +269,7 @@ def remove_list_redundancies(lst: Reversible[H]) -> list[H]:
269
269
return reversed_result
270
270
271
271
272
- def remove_nones (sequence : Iterable ) -> list :
272
+ def remove_nones (sequence : Iterable [ T | None ] ) -> list [ T ] :
273
273
"""Removes elements where bool(x) evaluates to False.
274
274
275
275
Examples
@@ -422,7 +422,7 @@ def tuplify(obj: Iterable[T]) -> tuple[T]: ...
422
422
def tuplify (obj : T ) -> tuple [T ]: ...
423
423
424
424
425
- def tuplify (obj ) :
425
+ def tuplify (obj : str | Iterable [ T ] | T ) -> tuple [ str ] | tuple [ T ] :
426
426
"""Converts obj to a tuple intelligently.
427
427
428
428
Examples
@@ -438,9 +438,9 @@ def tuplify(obj):
438
438
"""
439
439
if isinstance (obj , str ):
440
440
return (obj ,)
441
- try :
441
+ if isinstance ( obj , Iterable ) :
442
442
return tuple (obj )
443
- except TypeError :
443
+ else :
444
444
return (obj ,)
445
445
446
446
0 commit comments