From 095fe0d649541636d7011e779214a146b4f32895 Mon Sep 17 00:00:00 2001 From: James Salvatore Date: Wed, 31 Aug 2022 23:25:13 -0500 Subject: [PATCH 1/1] docs: adds ExitStack alternative to future_style.md (#3247) Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com> Co-authored-by: Jelle Zijlstra --- docs/conf.py | 2 +- docs/the_black_code_style/future_style.md | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 8da9c39..7fc4f8f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -55,7 +55,7 @@ make_pypi_svg(release) # -- General configuration --------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. -needs_sphinx = "3.0" +needs_sphinx = "4.4" # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom diff --git a/docs/the_black_code_style/future_style.md b/docs/the_black_code_style/future_style.md index fab4bca..a17d9a1 100644 --- a/docs/the_black_code_style/future_style.md +++ b/docs/the_black_code_style/future_style.md @@ -34,6 +34,19 @@ with \ Although when the target version is Python 3.9 or higher, _Black_ will use parentheses instead since they're allowed in Python 3.9 and higher. +An alternative to consider if the backslashes in the above formatting are undesirable is +to use {external:py:obj}`contextlib.ExitStack` to combine context managers in the +following way: + +```python +with contextlib.ExitStack() as exit_stack: + cm1 = exit_stack.enter_context(make_context_manager(1)) + cm2 = exit_stack.enter_context(make_context_manager(2)) + cm3 = exit_stack.enter_context(make_context_manager(3)) + cm4 = exit_stack.enter_context(make_context_manager(4)) + ... +``` + ## Preview style Experimental, potentially disruptive style changes are gathered under the `--preview` -- 2.39.5