[issue46838] Parameters and arguments parser syntax error improvments

2022-03-22 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:


New changeset 7d810b6a4eab6eba689acc5bb05f85515478d690 by Pablo Galindo Salgado 
in branch 'main':
bpo-46838: Syntax error improvements for function definitions (GH-31590)
https://github.com/python/cpython/commit/7d810b6a4eab6eba689acc5bb05f85515478d690


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46838] Parameters and arguments parser syntax error improvments

2022-02-25 Thread Andrej Klychin


Andrej Klychin  added the comment:

@terry.reedy, I based that error message on current >>> foo(**{}, *())
SyntaxError: iterable argument unpacking follows keyword argument unpacking

and >>> foo(__debug__=True)
SyntaxError: cannot assign to __debug__

but the final error message could be anything if it explicitly says "what's 
wrong".

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46838] Parameters and arguments parser syntax error improvments

2022-02-25 Thread Andre Roberge


Change by Andre Roberge :


--
nosy: +aroberge

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46838] Parameters and arguments parser syntax error improvments

2022-02-25 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
keywords: +patch
pull_requests: +29713
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/31590

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46838] Parameters and arguments parser syntax error improvments

2022-02-25 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

With two exceptions, nice suggestions if feasible.

>>> def foo(*args=None): pass
SyntaxError: * argument cannot have default value

>>> def foo(**kwargs=None): pass
SyntaxError: ** argument cannot have default value

Good.

>>> foo(*args=[0])
SyntaxError: cannot assign to iterable argument unpacking

>>> foo(**args={"a": None})
SyntaxError: cannot assign to keyword argument unpacking

Incomprehensible.  It seems to me that these should have same message as first 
two; message should not depend on proposed default.

--
nosy: +terry.reedy

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46838] Parameters and arguments parser syntax error improvments

2022-02-23 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:

Thanks a lot for the suggestions! I will try to give these a go to see if we 
can get them implemented. Parameter parsing is a bit hairy so not sure how 
lucky we will be but all of them make sense!

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46838] Parameters and arguments parser syntax error improvments

2022-02-23 Thread Andrej Klychin


Andrej Klychin  added the comment:

I also sometimes write def foo(pos_only, /*, kwarg): pass. Perhaps this can be 
special cased with 
SyntaxError: expected comma between / and *

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46838] Parameters and arguments parser syntax error improvments

2022-02-23 Thread Andrej Klychin


New submission from Andrej Klychin :

I saw that pablogsal welcomed improvments to the parser's suggestions, so here 
are the messages for parameters and arguments lists I think should be written 
instead of the current generic "invalid syntax".

>>> def foo(*arg, *arg): pass
SyntaxError: * argument may appear only once

>>> def foo(**arg, **arg): pass
SyntaxError: ** argument may appear only once

>>> def foo(arg1, /, arg2, /, arg3): pass
SyntaxError: / may appear only once

>>> def foo(*args, /, arg): pass
SyntaxError: / must be ahead of *

>>> def foo(/, arg): pass
SyntaxError: at least one argument must precede /

>>> def foo(arg=): pass
SyntaxError: expected default value expression

>>> def foo(*args=None): pass
SyntaxError: * argument cannot have default value

>>> def foo(**kwargs=None): pass
SyntaxError: ** argument cannot have default value

>>> foo(*args=[0])
SyntaxError: cannot assign to iterable argument unpacking

>>> foo(**args={"a": None})
SyntaxError: cannot assign to keyword argument unpacking

>>> foo(arg=)
SyntaxError: expected argument value expression

--
components: Parser
messages: 413856
nosy: Andy_kl, lys.nikolaou, pablogsal
priority: normal
severity: normal
status: open
title: Parameters and arguments parser syntax error improvments
type: enhancement
versions: Python 3.11

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com