gpython icon indicating copy to clipboard operation
gpython copied to clipboard

def a(x=3, b, c) should not be accepted

Open corona10 opened this issue 6 years ago • 4 comments

But accepted in gpython it should be raised Syntax error.

cpython

>>> def a(x=3, b, c):
...     pass
...
  File "<stdin>", line 1
SyntaxError: non-default argument follows default argument

gpython

>>> def a(x=3, b, c):
...     pass
...
>>> a()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    FIXME line of source goes here
TypeError: "a() missing 2 required positional arguments: 'x' and 'b'"

corona10 avatar Sep 23 '19 02:09 corona10

Or more general: all kwargs must be declared last. The following currently also works in gpython:

def a(b, x=3, c):
  pass

ghost avatar Sep 23 '19 15:09 ghost

I think this is probably a bug in parser/grammar.y. This FIXME looks relevant ;-)

https://github.com/go-python/gpython/blob/4b347aa2bb5acd7fdd2fcb9a52b463f6c5535740/parser/grammar.y#L464

ncw avatar Sep 28 '19 17:09 ncw

If no one tried this issue, can I try it?

HyeockJinKim avatar Oct 11 '19 07:10 HyeockJinKim

@HyeockJinKim Yes please

corona10 avatar Oct 11 '19 11:10 corona10