Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap multiple context managers in parentheses when targeting Python 3.9+ #3489

Merged
merged 6 commits into from
Jan 20, 2023

Conversation

yilei
Copy link
Contributor

@yilei yilei commented Jan 10, 2023

Description

Fixes #3486.

This also fixes the target version detection logic for parenthesized context managers (3.9) and match statements (3.10). But as far as I can tell, this didn't have user visible impact (until this PR).

I added a dedicated test data folder preview_context_managers, because this relies on the version detection logic when --target-version is not explicitly specified.

Checklist - did you ...

  • Add an entry in CHANGES.md if necessary?
  • Add / update tests if necessary?
  • Add new / update outdated documentation?

@github-actions
Copy link

github-actions bot commented Jan 10, 2023

diff-shades reports zero changes comparing this PR (95bca0f) to main (18fb884).


What is this? | Workflow run | diff-shades documentation

@yilei
Copy link
Contributor Author

yilei commented Jan 10, 2023

I manually ran diff-shades analyze base.json --work-dir projects-cache --force-preview-style -- --target-version=py39 forcing to target 3.9. The attached diffs look good.

cm.diff.zip

First example:

╭──────────────────────── Summary ─────────────────────────╮
│ 12 projects & 29 files changed / 608 changes [+347/-261] │
│                                                          │
│ ... out of 2 384 528 lines, 11 521 files & 23 projects   │
╰──────────────────────────────────────────────────────────╯

[aioexabgp - https://github.com/cooperlees/aioexabgp.git]
╰─> revision fc83c5c705e3c818934ce0cdd04d6169a6977996
--- a/aioexabgp:aioexabgp/tests/fibs_tests.py
+++ b/aioexabgp:aioexabgp/tests/fibs_tests.py
@@ -190,31 +190,37 @@
                 )
             )

     def test_del_all_routes(self) -> None:
         # Test delete all with a nexthop
-        with patch(
-            f"{BASE_MODULE}.LinuxFib.get_route_table",
-            fibs_tests_fixtures.mocked_get_route_table,
-        ), patch(
-            f"{BASE_MODULE}.LinuxFib.del_route", return_value=True
-        ) as mock_del_route:
+        with (
+            patch(
+                f"{BASE_MODULE}.LinuxFib.get_route_table",
+                fibs_tests_fixtures.mocked_get_route_table,
+            ),
+            patch(
+                f"{BASE_MODULE}.LinuxFib.del_route", return_value=True
+            ) as mock_del_route,
+        ):
             self.assertTrue(
                 self.loop.run_until_complete(
                     self.lfib.del_all_routes(ip_address("fd00::4"))
                 )
             )
             # 1 prefix/route from v4 and 1 from v6 table
             self.assertEqual(2, mock_del_route.call_count)

         # Test no next hope and ensure we delete them all
-        with patch(
-            f"{BASE_MODULE}.LinuxFib.get_route_table",
-            fibs_tests_fixtures.mocked_get_route_table,
-        ), patch(
-            f"{BASE_MODULE}.LinuxFib.del_route", return_value=True
-        ) as mock_del_route:
+        with (
+            patch(
+                f"{BASE_MODULE}.LinuxFib.get_route_table",
+                fibs_tests_fixtures.mocked_get_route_table,
+            ),
+            patch(
+                f"{BASE_MODULE}.LinuxFib.del_route", return_value=True
+            ) as mock_del_route,
+        ):
             self.assertTrue(
                 self.loop.run_until_complete(self.lfib.del_all_routes(None))
             )
             # 2 prefix/route from v4 and 1 from v6 table
             self.assertEqual(3, mock_del_route.call_count)

@JelleZijlstra JelleZijlstra merged commit 91e1e13 into psf:main Jan 20, 2023
@JelleZijlstra
Copy link
Collaborator

Thank you as always!

@yilei yilei deleted the cm branch January 20, 2023 18:27
yilei added a commit to yilei/black that referenced this pull request Feb 2, 2023
copybara-service bot pushed a commit to google/pyink that referenced this pull request Feb 6, 2023
Noticeable style changes:

1. Parenthesize multiple context managers psf#3489.

The following style changes are temporarily disabled when `--preview` is used together with `--pyink`:

2. Format unicode escape sequences psf#2916.
3. Parenthesize conditional expressions psf#2278.

PiperOrigin-RevId: 507485670
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrap multiple context managers in parens when targeting Python 3.10+
2 participants