Skip to content

Commit 0cc99c8

Browse files
bpo-32482: Fix suspicious code in tests for syntax and grammar. (#5086)
1 parent 811b287 commit 0cc99c8

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
@@ -1091,7 +1091,6 @@ def test_try(self):
10911091
try: 1/0
10921092
except EOFError: pass
10931093
except TypeError as msg: pass
1094-
except RuntimeError as msg: pass
10951094
except: pass
10961095
else: pass
10971096
try: 1/0
@@ -1200,7 +1199,7 @@ def test_selectors(self):
12001199
d[1,2] = 3
12011200
d[1,2,3] = 4
12021201
L = list(d)
1203-
L.sort(key=lambda x: x if isinstance(x, tuple) else ())
1202+
L.sort(key=lambda x: (type(x).__name__, x))
12041203
self.assertEqual(str(L), '[1, (1,), (1, 2), (1, 2, 3)]')
12051204

12061205
def test_atoms(self):

Lib/test/test_syntax.py

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

670670
def test_kwargs_last2(self):
671-
self._check_error("int(**{base: 10}, '2')",
671+
self._check_error("int(**{'base': 10}, '2')",
672672
"positional argument follows "
673673
"keyword argument unpacking")
674674

675675
def test_kwargs_last3(self):
676-
self._check_error("int(**{base: 10}, *['2'])",
676+
self._check_error("int(**{'base': 10}, *['2'])",
677677
"iterable argument unpacking follows "
678678
"keyword argument unpacking")
679679

0 commit comments

Comments
 (0)