Staging
v0.5.1
https://github.com/python/cpython
Revision 6e8dcdaaa49d4313bf9fab9f9923ca5828fbb10e authored by Joongi Kim on 02 November 2020, 08:02:48 UTC, committed by GitHub on 02 November 2020, 08:02:48 UTC


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.
1 parent e9208f0
History
Tip revision: 6e8dcdaaa49d4313bf9fab9f9923ca5828fbb10e authored by Joongi Kim on 02 November 2020, 08:02:48 UTC
bpo-41229: Update docs for explicit aclose()-required cases and add contextlib.aclosing() method (GH-21545)
Tip revision: 6e8dcda
File Mode Size
bdist_wininst
clinic
icons
layout
WinMain.c -rw-r--r-- 449 bytes
_msi.c -rw-r--r-- 36.3 KB
_testconsole.c -rw-r--r-- 3.2 KB
classicAppCompat.can.xml -rw-r--r-- 3.9 KB
classicAppCompat.cat -rw-r--r-- 10.7 KB
classicAppCompat.sccd -rw-r--r-- 18.1 KB
config.c -rw-r--r-- 5.4 KB
crtlicense.txt -rw-r--r-- 1.7 KB
dl_nt.c -rw-r--r-- 808 bytes
empty.c -rw-r--r-- 137 bytes
errmap.h -rw-r--r-- 4.9 KB
errmap.mak -rw-r--r-- 95 bytes
frozen_dllmain.c -rw-r--r-- 3.9 KB
getpathp.c -rw-r--r-- 34.0 KB
invalid_parameter_handler.c -rw-r--r-- 549 bytes
launcher.c -rw-r--r-- 64.5 KB
msvcrtmodule.c -rw-r--r-- 16.0 KB
pyconfig.h -rw-r--r-- 19.8 KB
pylauncher.rc -rw-r--r-- 1.5 KB
pyshellext.cpp -rw-r--r-- 18.3 KB
pyshellext.def -rw-r--r-- 120 bytes
pyshellext.rc -rw-r--r-- 1.1 KB
python.manifest -rw-r--r-- 1.3 KB
python3dll.c -rw-r--r-- 26.0 KB
python_exe.rc -rw-r--r-- 1.2 KB
python_nt.rc -rw-r--r-- 1.1 KB
python_uwp.cpp -rw-r--r-- 6.5 KB
python_ver_rc.h -rw-r--r-- 969 bytes
pythonw_exe.rc -rw-r--r-- 1.2 KB
readme.txt -rw-r--r-- 3.5 KB
sqlite3.rc -rw-r--r-- 1.3 KB
store_info.txt -rw-r--r-- 6.2 KB
testpy.py -rw-r--r-- 831 bytes
validate_ucrtbase.py -rw-r--r-- 2.7 KB
winreg.c -rw-r--r-- 64.6 KB
winsound.c -rw-r--r-- 6.5 KB

readme.txt

back to top