Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ invalid_parameters:
| (slash_no_default | slash_with_default) param_maybe_default* a='/' {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "/ may appear only once") }
| slash_no_default? param_no_default* invalid_parameters_helper a=param_no_default {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "parameter without a default follows parameter with a default") }
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "positional parameter without a default follows parameter with a default") }
| param_no_default* a='(' param_no_default+ ','? b=')' {
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "Function parameters cannot be parenthesized") }
| (slash_no_default | slash_with_default)? param_maybe_default* '*' (',' | param_no_default) param_maybe_default* a='/' {
Expand Down Expand Up @@ -1287,7 +1287,7 @@ invalid_lambda_parameters:
| (lambda_slash_no_default | lambda_slash_with_default) lambda_param_maybe_default* a='/' {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "/ may appear only once") }
| lambda_slash_no_default? lambda_param_no_default* invalid_lambda_parameters_helper a=lambda_param_no_default {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "parameter without a default follows parameter with a default") }
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "positional parameter without a default follows parameter with a default") }
| lambda_param_no_default* a='(' ','.lambda_param+ ','? b=')' {
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "Lambda expression parameters cannot be parenthesized") }
| (lambda_slash_no_default | lambda_slash_with_default)? lambda_param_maybe_default* '*' (',' | lambda_param_no_default) lambda_param_maybe_default* a='/' {
Expand Down
30 changes: 15 additions & 15 deletions Lib/test/test_positional_only_arg.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ def assertRaisesSyntaxError(self, codestr, regex="invalid syntax"):
compile(codestr + "\n", "<test>", "single")

def test_invalid_syntax_errors(self):
check_syntax_error(self, "def f(a, b = 5, /, c): pass", "parameter without a default follows parameter with a default")
check_syntax_error(self, "def f(a = 5, b, /, c): pass", "parameter without a default follows parameter with a default")
check_syntax_error(self, "def f(a = 5, b=1, /, c, *, d=2): pass", "parameter without a default follows parameter with a default")
check_syntax_error(self, "def f(a = 5, b, /): pass", "parameter without a default follows parameter with a default")
check_syntax_error(self, "def f(a, /, b = 5, c): pass", "parameter without a default follows parameter with a default")
check_syntax_error(self, "def f(a, b = 5, /, c): pass", "positional parameter without a default follows parameter with a default ")
check_syntax_error(self, "def f(a = 5, b, /, c): pass", "positional parameter without a default follows parameter with a default ")
check_syntax_error(self, "def f(a = 5, b=1, /, c, *, d=2): pass", "positional parameter without a default follows parameter with a default ")
check_syntax_error(self, "def f(a = 5, b, /): pass", "positional parameter without a default follows parameter with a default ")
check_syntax_error(self, "def f(a, /, b = 5, c): pass", "positional parameter without a default follows parameter with a default ")
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")
Expand All @@ -46,11 +46,11 @@ def test_invalid_syntax_errors(self):
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", "parameter without a default follows parameter with a default")
check_syntax_error(self, "async def f(a = 5, b, /, c): pass", "parameter without a default follows parameter with a default")
check_syntax_error(self, "async def f(a = 5, b=1, /, c, d=2): pass", "parameter without a default follows parameter with a default")
check_syntax_error(self, "async def f(a = 5, b, /): pass", "parameter without a default follows parameter with a default")
check_syntax_error(self, "async def f(a, /, b = 5, c): pass", "parameter without a default follows parameter with a default")
check_syntax_error(self, "async def f(a, b = 5, /, c): pass", "positional parameter without a default follows parameter with a default ")
check_syntax_error(self, "async def f(a = 5, b, /, c): pass", "positional parameter without a default follows parameter with a default ")
check_syntax_error(self, "async def f(a = 5, b=1, /, c, d=2): pass", "positional parameter without a default follows parameter with a default ")
check_syntax_error(self, "async def f(a = 5, b, /): pass", "positional parameter without a default follows parameter with a default ")
check_syntax_error(self, "async def f(a, /, b = 5, c): pass", "positional parameter without a default follows parameter with a default ")
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")
Expand Down Expand Up @@ -234,11 +234,11 @@ def test_lambdas(self):
self.assertEqual(x(1, 2), 3)

def test_invalid_syntax_lambda(self):
check_syntax_error(self, "lambda a, b = 5, /, c: None", "parameter without a default follows parameter with a default")
check_syntax_error(self, "lambda a = 5, b, /, c: None", "parameter without a default follows parameter with a default")
check_syntax_error(self, "lambda a = 5, b=1, /, c, *, d=2: None", "parameter without a default follows parameter with a default")
check_syntax_error(self, "lambda a = 5, b, /: None", "parameter without a default follows parameter with a default")
check_syntax_error(self, "lambda a, /, b = 5, c: None", "parameter without a default follows parameter with a default")
check_syntax_error(self, "lambda a, b = 5, /, c: None", "positional parameter without a default follows parameter with a default ")
check_syntax_error(self, "lambda a = 5, b, /, c: None", "positional parameter without a default follows parameter with a default ")
check_syntax_error(self, "lambda a = 5, b=1, /, c, *, d=2: None", "positional parameter without a default follows parameter with a default ")
check_syntax_error(self, "lambda a = 5, b, /: None", "positional parameter without a default follows parameter with a default ")
check_syntax_error(self, "lambda a, /, b = 5, c: None", "positional parameter without a default follows parameter with a default ")
check_syntax_error(self, "lambda *args, /: None")
check_syntax_error(self, "lambda *args, a, /: None")
check_syntax_error(self, "lambda **kwargs, /: None")
Expand Down
8 changes: 4 additions & 4 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,12 @@
>>> def f(x, y=1, z):
... pass
Traceback (most recent call last):
SyntaxError: parameter without a default follows parameter with a default
SyntaxError: positional parameter without a default follows parameter with a default

>>> def f(x, /, y=1, z):
... pass
Traceback (most recent call last):
SyntaxError: parameter without a default follows parameter with a default
SyntaxError: positional parameter without a default follows parameter with a default

>>> def f(x, None):
... pass
Expand Down Expand Up @@ -622,11 +622,11 @@

>>> lambda a,d=3,c: None
Traceback (most recent call last):
SyntaxError: parameter without a default follows parameter with a default
SyntaxError: positional parameter without a default follows parameter with a default

>>> lambda a,/,d=3,c: None
Traceback (most recent call last):
SyntaxError: parameter without a default follows parameter with a default
SyntaxError: positional parameter without a default follows parameter with a default

>>> import ast; ast.parse('''
... def f(
Expand Down
4 changes: 2 additions & 2 deletions Parser/parser.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading