Skip to content

Commit a70d5ff

Browse files
miss-islingtonserhiy-storchaka
authored andcommitted
bpo-32482: Fix suspicious code in tests for syntax and grammar. (GH-5086) (#5095)
(cherry picked from commit 0cc99c8)
1 parent 1e6d852 commit a70d5ff

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

Lib/test/test_grammar.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,10 @@ def f(*args, **kwargs):
575575
self.assertEqual(f(spam='fried', **{'eggs':'scrambled'}),
576576
((), {'eggs':'scrambled', 'spam':'fried'}))
577577

578+
# Check ast errors in *args and *kwargs
579+
check_syntax_error(self, "f(*g(1=2))")
580+
check_syntax_error(self, "f(**g(1=2))")
581+
578582
# argument annotation tests
579583
def f(x) -> list: pass
580584
self.assertEqual(f.__annotations__, {'return': list})
@@ -616,10 +620,6 @@ def f(x=1): return closure
616620
def f(*, k=1): return closure
617621
def f() -> int: return closure
618622

619-
# Check ast errors in *args and *kwargs
620-
check_syntax_error(self, "f(*g(1=2))")
621-
check_syntax_error(self, "f(**g(1=2))")
622-
623623
# Check trailing commas are permitted in funcdef argument list
624624
def f(a,): pass
625625
def f(*args,): pass
@@ -1056,7 +1056,6 @@ def test_try(self):
10561056
try: 1/0
10571057
except EOFError: pass
10581058
except TypeError as msg: pass
1059-
except RuntimeError as msg: pass
10601059
except: pass
10611060
else: pass
10621061
try: 1/0
@@ -1165,7 +1164,7 @@ def test_selectors(self):
11651164
d[1,2] = 3
11661165
d[1,2,3] = 4
11671166
L = list(d)
1168-
L.sort(key=lambda x: x if isinstance(x, tuple) else ())
1167+
L.sort(key=lambda x: (type(x).__name__, x))
11691168
self.assertEqual(str(L), '[1, (1,), (1, 2), (1, 2, 3)]')
11701169

11711170
def test_atoms(self):

Lib/test/test_syntax.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,12 +600,12 @@ def test_kwargs_last(self):
600600
"positional argument follows keyword argument")
601601

602602
def test_kwargs_last2(self):
603-
self._check_error("int(**{base: 10}, '2')",
603+
self._check_error("int(**{'base': 10}, '2')",
604604
"positional argument follows "
605605
"keyword argument unpacking")
606606

607607
def test_kwargs_last3(self):
608-
self._check_error("int(**{base: 10}, *['2'])",
608+
self._check_error("int(**{'base': 10}, *['2'])",
609609
"iterable argument unpacking follows "
610610
"keyword argument unpacking")
611611

0 commit comments

Comments
 (0)