-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed an issue where using
partial
on a generator function in pytho…
…n 3.5 was raising a `SyntaxError`. Fixed #79
- Loading branch information
Sylvain MARIE
committed
Jan 7, 2022
1 parent
e4f4b5b
commit 2101bca
Showing
4 changed files
with
45 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Authors: Sylvain MARIE <[email protected]> | ||
# + All contributors to <https://github.com/smarie/python-makefun> | ||
# | ||
# License: 3-clause BSD, <https://github.com/smarie/python-makefun/blob/master/LICENSE> | ||
from itertools import chain | ||
|
||
from makefun.main import wraps | ||
|
||
|
||
def make_partial_using_async_for_in_yield(new_sig, f, *preset_pos_args, **preset_kwargs): | ||
""" | ||
Makes a 'partial' when f is a async generator and python is new enough to support `async for v in f(): yield v` | ||
:param new_sig: | ||
:param f: | ||
:param presets: | ||
:return: | ||
""" | ||
|
||
@wraps(f, new_sig=new_sig) | ||
async def partial_f(*args, **kwargs): | ||
kwargs.update(preset_kwargs) | ||
async for v in f(*chain(preset_pos_args, args), **kwargs): | ||
yield v | ||
|
||
return partial_f |
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