| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
| |
Automerge-Triggered-By: GH:asvetlov
|
|
|
|
|
| |
(GH-21870)
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
|
|
|
|
| |
Co-authored-by: Yury Selivanov <yury@edgedb.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
contextlib.aclosing() method (GH-21545)
This is a PR to:
* Add `contextlib.aclosing` which ia analogous to `contextlib.closing` but for async-generators with an explicit test case for [bpo-41229]()
* Update the docs to describe when we need explicit `aclose()` invocation.
which are motivated by the following issues, articles, and examples:
* [bpo-41229]()
* https://github.com/njsmith/async_generator
* https://vorpus.org/blog/some-thoughts-on-asynchronous-api-design-in-a-post-asyncawait-world/#cleanup-in-generators-and-async-generators
* https://www.python.org/dev/peps/pep-0533/
* https://github.com/achimnol/aiotools/blob/ef7bf0cea7af/src/aiotools/context.py#L152
Particuarly regarding [PEP-533](https://www.python.org/dev/peps/pep-0533/), its acceptance (`__aiterclose__()`) would make this little addition of `contextlib.aclosing()` unnecessary for most use cases, but until then this could serve as a good counterpart and analogy to `contextlib.closing()`. The same applies for `contextlib.closing` with `__iterclose__()`.
Also, still there are other use cases, e.g., when working with non-generator objects with `aclose()` methods.
|
|
|
|
|
|
|
|
|
|
|
|
| |
This implements things like `list[int]`,
which returns an object of type `types.GenericAlias`.
This object mostly acts as a proxy for `list`,
but has attributes `__origin__` and `__args__`
that allow recovering the parts (with values `list` and `(int,)`.
There is also an approximate notion of type variables;
e.g. `list[T]` has a `__parameters__` attribute equal to `(T,)`.
Type variables are objects of type `typing.TypeVar`.
|
|
|
| |
Turn deprecation warnings added in 3.8 into TypeError.
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Deprecated passing the following arguments as keyword arguments:
- "func" in functools.partialmethod(), weakref.finalize(),
profile.Profile.runcall(), cProfile.Profile.runcall(),
bdb.Bdb.runcall(), trace.Trace.runfunc() and
curses.wrapper().
- "function" in unittest.addModuleCleanup() and
unittest.TestCase.addCleanup().
- "fn" in the submit() method of concurrent.futures.ThreadPoolExecutor
and concurrent.futures.ProcessPoolExecutor.
- "callback" in contextlib.ExitStack.callback(),
contextlib.AsyncExitStack.callback() and
contextlib.AsyncExitStack.push_async_callback().
- "c" and "typeid" in the create() method of multiprocessing.managers.Server
and multiprocessing.managers.SharedMemoryServer.
- "obj" in weakref.finalize().
Also allowed to pass arbitrary keyword arguments (even "self" and "func")
if the above arguments are passed as positional argument.
|
|
|
|
| |
(GH-7467)
|
|
|
|
|
|
| |
ExitStack (GH-6456)
`MethodType` has the exact semantics that `ExitStack` needs,
so we can avoid creating a Python level closure.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The arguments to a generator function which is declared as a
contextmanager are stored inside the context manager, and
thus are kept alive, even when it is used as a regular context
manager, and not as a function decorator (where it needs
the original arguments to recreate the generator on each
call).
This is a possible unnecessary memory leak, so this changes
contextmanager.__enter__ to release the saved arguments,
as that method being called means that particular CM instance
isn't going to need to recreate the underlying generator.
Patch by Martin Teichmann.
|
| |
|
| |
|
|
|
|
|
| |
Adds a simpler and faster alternative to ExitStack for handling
single optional context managers without having to change the
lexical structure of your code.
|
|
|
|
|
| |
contextlib.AbstractContextManager now supports anti-registration
by setting __enter__ = None or __exit__ = None, following the pattern
introduced in bpo-25958.
|
| |
|
|
|
|
|
|
|
|
|
|
| |
(GH-949)
contextlib._GeneratorContextManager.__exit__ includes a special case to deal with
PEP 479 RuntimeErrors created when `StopIteration` is thrown into the context
manager body.
Previously this check was too permissive, and undid one level of chaining on *all*
RuntimeError instances, not just those that wrapped a StopIteration instance.
|
|
|
| |
Moved explicit raise from inside try to try...else.
|
|
|
|
|
|
| |
It took me quite a bit to figure out what this was referring to,
since the given issue number is wrong, and the original commit
message I found through git blame lists a different, also wrong
issue number... see https://bugs.python.org/issue27122#msg279449
|
|\
| |
| |
| |
| |
| |
| | |
managed by a contextlib.ExitStack() and one of the exit stack
generators catches and raises it in a chain, do not re-raise the
original exception when exiting, let the new chained one through.
This avoids the PEP 479 bug described in issue25782.
|
| |
| |
| |
| |
| |
| |
| | |
managed by a contextlib.ExitStack() and one of the exit stack
generators catches and raises it in a chain, do not re-raise the
original exception when exiting, let the new chained one through.
This avoids the PEP 479 bug described in issue25782.
|
| | |
|
|/
|
|
| |
typing.ContextManager.
|
|\
| |
| |
| | |
keyword arguments called "func" and "self". Patch by Martin Panter.
|
| |
| |
| |
| | |
keyword arguments called "func" and "self". Patch by Martin Panter.
|
| |
| |
| |
| | |
Closes issue #22906.
|
|/ |
|
|\ |
|
| |
| |
| |
| |
| |
| |
| | |
- Alex J Burke noticed a debugging raise in the commit that
fixed the original bug reported in issue 20317
- this showed that multiple iterations through the affected
loop wasn't actually being tested
|
|\ \
| |/ |
|
| | |
|
| | |
|
| |
| |
| |
| |
| |
| |
| | |
- added test cases to ensure docstrings are reasonable
- also updates various comments in contextlib for accuracy
- identifed #19404 as an issue making it difficult to provide
good help output on generator based context manager instances
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
- explain single use, reusable and reentrant in docs
- converted suppress to a reentrant class based impl
- converted redirect_stdout to a reusable impl
- moved both suppress and redirect_stdout behind a functional
facade
- added reentrancy tests for the updated suppress
- added reusability tests for the updated redirect_stdio
- slightly cleaned up an exception from contextmanager
|
| |
| |
| |
| | |
Patch by Zero Piraeus.
|
| | |
|
| | |
|
|\ \
| |/ |
|
| |
| |
| |
| | |
Report and patch by Hrvoje Nikšić
|
|\ \
| |/ |
|
|/ |
|
|\
| |
| |
| | |
Patch by Serhiy Storchaka.
|
| | |
|
| |
| |
| |
| | |
(Patch by Alon Horev)
|
| |
| |
| |
| | |
contextlib.nested API
|
|/
|
|
| |
A patch from Vincent Legoll.
|
| |
|
|
|
|
| |
described in the docs. Initial patch by Ysj Ray.
|
|
|
|
| |
private by renaming it to `_GeneratorContextManager`.
|