From 3240a2412ff74d00a0dc8075e5d9de6a4da7bf3f Mon Sep 17 00:00:00 2001 From: James Salvatore Date: Wed, 31 Aug 2022 13:49:53 -0500 Subject: [PATCH 1/5] docs: adds ExitStack alternative to future_style.md --- docs/the_black_code_style/future_style.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/the_black_code_style/future_style.md b/docs/the_black_code_style/future_style.md index fab4bca120e..964401a7e8b 100644 --- a/docs/the_black_code_style/future_style.md +++ b/docs/the_black_code_style/future_style.md @@ -34,6 +34,17 @@ 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 is undesirable is to use [`contextlib.ExitStack`](https://docs.python.org/3.9/library/contextlib.html#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` From a26bcafe94ce80ef49ec6f5c1ef34dc568f452fb Mon Sep 17 00:00:00 2001 From: James Salvatore Date: Wed, 31 Aug 2022 14:14:18 -0500 Subject: [PATCH 2/5] prettier linting; --- docs/the_black_code_style/future_style.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/the_black_code_style/future_style.md b/docs/the_black_code_style/future_style.md index 964401a7e8b..981f9feb4d1 100644 --- a/docs/the_black_code_style/future_style.md +++ b/docs/the_black_code_style/future_style.md @@ -34,7 +34,10 @@ 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 is undesirable is to use [`contextlib.ExitStack`](https://docs.python.org/3.9/library/contextlib.html#contextlib.ExitStack) to combine context managers in the following way: +An alternative to consider if the backslashes in the above formatting is undesirable is +to use +[`contextlib.ExitStack`](https://docs.python.org/3.9/library/contextlib.html#contextlib.ExitStack) +to combine context managers in the following way: ```python with contextlib.ExitStack() as exit_stack: From 1037b9b201c61d8d481e37440508f70df9632725 Mon Sep 17 00:00:00 2001 From: James Salvatore Date: Wed, 31 Aug 2022 14:22:40 -0500 Subject: [PATCH 3/5] use intersphinx instead of hardcoding link; --- docs/the_black_code_style/future_style.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/the_black_code_style/future_style.md b/docs/the_black_code_style/future_style.md index 981f9feb4d1..6b587cdde5b 100644 --- a/docs/the_black_code_style/future_style.md +++ b/docs/the_black_code_style/future_style.md @@ -35,9 +35,8 @@ Although when the target version is Python 3.9 or higher, _Black_ will use paren instead since they're allowed in Python 3.9 and higher. An alternative to consider if the backslashes in the above formatting is undesirable is -to use -[`contextlib.ExitStack`](https://docs.python.org/3.9/library/contextlib.html#contextlib.ExitStack) -to combine context managers in the following way: +to use {external:py:obj}`contextlib.ExitStack` to combine context managers in the +following way: ```python with contextlib.ExitStack() as exit_stack: From 68750a3b06b234578333e6c752d33d4fd4264373 Mon Sep 17 00:00:00 2001 From: Richard Si <63936253+ichard26@users.noreply.github.com> Date: Wed, 31 Aug 2022 15:25:20 -0400 Subject: [PATCH 4/5] The external role is actually a Sphinx 4.4+ feature --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 8da9c39ac41..7fc4f8f589e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -55,7 +55,7 @@ def make_pypi_svg(version: str) -> None: # -- 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 From 5202438c61fea36c3c6962e59d0094fd0226f1cd Mon Sep 17 00:00:00 2001 From: James Salvatore Date: Wed, 31 Aug 2022 21:06:30 -0500 Subject: [PATCH 5/5] Update docs/the_black_code_style/future_style.md Co-authored-by: Jelle Zijlstra --- docs/the_black_code_style/future_style.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/the_black_code_style/future_style.md b/docs/the_black_code_style/future_style.md index 6b587cdde5b..a17d9a10673 100644 --- a/docs/the_black_code_style/future_style.md +++ b/docs/the_black_code_style/future_style.md @@ -34,7 +34,7 @@ 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 is undesirable is +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: