On 30 August 2017 at 16:40, Nick Coghlan <ncoghlan at gmail.com> wrote: > Writing an "update_parent_context" decorator is also trivial (and will > work for both sync and async generators): > > def update_parent_context(gf): > @functools.wraps(gf): > def wrapper(*args, **kwds): > gen = gf(*args, **kwds): > gen.__logical_context__ = None > return gen > return wrapper [snip] > While I'm not sure how much practical use it will see, I do think it's > important to preserve the *ability* to transparently refactor > generators using yield from - I'm just OK with such a refactoring > becoming "yield from update_parent_context(subgen())" instead of the > current "yield from subgen()" (as I think *not* updating the parent > context is a better default than updating it). Oops, I got mixed up between whether I thought this should be a decorator or an explicitly called helper function. One option would be to provide both: def update_parent_context(gen): ""Configures a generator-iterator to update its caller's context variables"""" gen.__logical_context__ = None return gen def updates_parent_context(gf): ""Wraps a generator function's instances with update_parent_context"""" @functools.wraps(gf): def wrapper(*args, **kwds): return update_parent_context(gf(*args, **kwds)) return wrapper Cheers, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4