summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_positional_only_arg.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_positional_only_arg.py')
-rw-r--r--Lib/test/test_positional_only_arg.py29
1 files changed, 18 insertions, 11 deletions
diff --git a/Lib/test/test_positional_only_arg.py b/Lib/test/test_positional_only_arg.py
index 0a9503e..3326900 100644
--- a/Lib/test/test_positional_only_arg.py
+++ b/Lib/test/test_positional_only_arg.py
@@ -3,6 +3,7 @@
import dis
import pickle
import unittest
+import sys
from test.support import check_syntax_error
@@ -23,10 +24,12 @@ class PositionalOnlyTestCase(unittest.TestCase):
compile(codestr + "\n", "<test>", "single")
def test_invalid_syntax_errors(self):
- check_syntax_error(self, "def f(a, b = 5, /, c): pass", "non-default argument follows default argument")
- check_syntax_error(self, "def f(a = 5, b, /, c): pass", "non-default argument follows default argument")
- check_syntax_error(self, "def f(a = 5, b=1, /, c, *, d=2): pass", "non-default argument follows default argument")
- check_syntax_error(self, "def f(a = 5, b, /): pass", "non-default argument follows default argument")
+ if not sys.flags.use_peg:
+ check_syntax_error(self, "def f(a, b = 5, /, c): pass", "non-default argument follows default argument")
+ check_syntax_error(self, "def f(a = 5, b, /, c): pass", "non-default argument follows default argument")
+ check_syntax_error(self, "def f(a = 5, b=1, /, c, *, d=2): pass", "non-default argument follows default argument")
+ check_syntax_error(self, "def f(a = 5, b, /): pass", "non-default argument follows default argument")
+
check_syntax_error(self, "def f(*args, /): pass")
check_syntax_error(self, "def f(*args, a, /): pass")
check_syntax_error(self, "def f(**kwargs, /): pass")
@@ -44,10 +47,12 @@ class PositionalOnlyTestCase(unittest.TestCase):
check_syntax_error(self, "def f(a, *, c, /, d, e): pass")
def test_invalid_syntax_errors_async(self):
- check_syntax_error(self, "async def f(a, b = 5, /, c): pass", "non-default argument follows default argument")
- check_syntax_error(self, "async def f(a = 5, b, /, c): pass", "non-default argument follows default argument")
- check_syntax_error(self, "async def f(a = 5, b=1, /, c, d=2): pass", "non-default argument follows default argument")
- check_syntax_error(self, "async def f(a = 5, b, /): pass", "non-default argument follows default argument")
+ if not sys.flags.use_peg:
+ check_syntax_error(self, "async def f(a, b = 5, /, c): pass", "non-default argument follows default argument")
+ check_syntax_error(self, "async def f(a = 5, b, /, c): pass", "non-default argument follows default argument")
+ check_syntax_error(self, "async def f(a = 5, b=1, /, c, d=2): pass", "non-default argument follows default argument")
+ check_syntax_error(self, "async def f(a = 5, b, /): pass", "non-default argument follows default argument")
+
check_syntax_error(self, "async def f(*args, /): pass")
check_syntax_error(self, "async def f(*args, a, /): pass")
check_syntax_error(self, "async def f(**kwargs, /): pass")
@@ -231,9 +236,11 @@ class PositionalOnlyTestCase(unittest.TestCase):
self.assertEqual(x(1, 2), 3)
def test_invalid_syntax_lambda(self):
- check_syntax_error(self, "lambda a, b = 5, /, c: None", "non-default argument follows default argument")
- check_syntax_error(self, "lambda a = 5, b, /, c: None", "non-default argument follows default argument")
- check_syntax_error(self, "lambda a = 5, b, /: None", "non-default argument follows default argument")
+ if not sys.flags.use_peg:
+ check_syntax_error(self, "lambda a, b = 5, /, c: None", "non-default argument follows default argument")
+ check_syntax_error(self, "lambda a = 5, b, /, c: None", "non-default argument follows default argument")
+ check_syntax_error(self, "lambda a = 5, b, /: None", "non-default argument follows default argument")
+
check_syntax_error(self, "lambda *args, /: None")
check_syntax_error(self, "lambda *args, a, /: None")
check_syntax_error(self, "lambda **kwargs, /: None")