[3.11] gh-104615: don't make unsafe swaps in apply_static_swaps (GH-104620). (#104636)

(cherry picked from commit 0589c6a4d3)
This commit is contained in:
Carl Meyer 2023-05-19 12:04:04 -06:00 committed by GitHub
parent d78c3bcf6f
commit 667e4ece98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 0 deletions

View file

@ -1064,6 +1064,24 @@ if 1:
with self.subTest(source):
self.assertEqual(actual_positions, expected_positions)
def test_apply_static_swaps(self):
def f(x, y):
a, a = x, y
return a
self.assertEqual(f("x", "y"), "y")
def test_apply_static_swaps_2(self):
def f(x, y, z):
a, b, a = x, y, z
return a
self.assertEqual(f("x", "y", "z"), "z")
def test_apply_static_swaps_3(self):
def f(x, y, z):
a, a, b = x, y, z
return a
self.assertEqual(f("x", "y", "z"), "y")
@requires_debug_ranges()
class TestSourcePositions(unittest.TestCase):