Decorator for iterator scoping / aclosing #74
maxfischer2781
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
While the pattern of
scoped_iter
andaclosing
solves resource leaks (see PEP 533 as always) it feels a bit unwieldy to use. Many functions need the resource in the entire scope and only scope it as a safety measure, not for functionality. The explicitasync with
for scoping increases the indentation level and pulls in unrelated resource management; a practical shortcoming is that adding scoping leads to a diff of the entire function due to indent.It would be interesting to have a decorator to automatically scope arguments to the entire function:
This isn't quite straightforward, since it needs a mechanism to identify which arguments to scope how. For example, many utilities of
asyncstdlib
itself take*iterables: AnyIterable[T]
and would have to scope each iterable.Beta Was this translation helpful? Give feedback.
All reactions