-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding the ability to pass lists and generators to .play() (#3365)
* adding the ability to pass lists and generators to .play() * fix for _AnimationBuilder * Changed handling of generators to accept lists of generators and normal arguments at the same time * Animation group handles generators * Refactored into own function for reusability * Fix typing * Fix typing --------- Co-authored-by: Jason Grace <[email protected]>
- Loading branch information
1 parent
fc42710
commit b69e1d7
Showing
4 changed files
with
68 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from __future__ import annotations | ||
|
||
from types import GeneratorType | ||
from typing import Iterable, TypeVar | ||
|
||
T = TypeVar("T") | ||
|
||
|
||
def flatten_iterable_parameters( | ||
args: Iterable[T | Iterable[T] | GeneratorType], | ||
) -> list[T]: | ||
"""Flattens an iterable of parameters into a list of parameters. | ||
Parameters | ||
---------- | ||
args | ||
The iterable of parameters to flatten. | ||
[(generator), [], (), ...] | ||
Returns | ||
------- | ||
:class:`list` | ||
The flattened list of parameters. | ||
""" | ||
flattened_parameters = [] | ||
for arg in args: | ||
if isinstance(arg, (Iterable, GeneratorType)): | ||
flattened_parameters.extend(arg) | ||
else: | ||
flattened_parameters.append(arg) | ||
return flattened_parameters |