[issue45801] Incorrect "Perhaps you forgot a comma" hint

2021-11-13 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:

I will close this but will try to think for another issue into an error for the 
parens -> braket. Thanks for opening the issue!

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

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



[issue45801] Incorrect "Perhaps you forgot a comma" hint

2021-11-13 Thread Andre Roberge


Andre Roberge  added the comment:

I understand.

I reported this issue when one of my newest tests failed with Python 3.10 and 
3.11. Actually, using friendly-traceback, using the location of the exception 
as indicated by cPython 3.10 and 3.11, here's part of the explanation it gives:

The following lines of code would not cause any `SyntaxError`:

sum + [i for i in [1, 2, 3] if i%2==0]
sum - [i for i in [1, 2, 3] if i%2==0]
sum * [i for i in [1, 2, 3] if i%2==0]
sum, [i for i in [1, 2, 3] if i%2==0]
Note: these are just some of the possible choices and that
some of them might raise other types of exceptions.

So, I agree with you that suggesting a comma would be appropriate.  (I also 
miss the suggestion of inserting an equal sign above).

Meanwhile, with prior versions of cPython, here's the suggestion that was 
offered:

You used square brackets, `[...]` instead of parentheses.
Write the following instead:

sum(i for i in [1, 2, 3] if i%2==0)

So, since using the suggestion currently by cPython (3.10, 3.11), one could get 
a syntactically valid statement by adding a comma, I cannot really argue that 
this is a bug. (Sorry, I should have checked in more details before.)

Therefore, I agree that this issue should probably be closed ... unless you 
find that suggesting a missing comma while there are many other possible 
operators that could be inserted could be considered as misleading.

--

___
Python tracker 

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



[issue45801] Incorrect "Perhaps you forgot a comma" hint

2021-11-13 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:

I think this is correct because if you add a comma, indeed is valid syntax:

>>> sum,[i for i in [1, 2, 3] if i%2==0]
(, [2])

Here the problem is that you are mentally mapping the construct to sum(...) 
where the parens are substituted with brackets, which is not what the parser 
sees, the parser sees two expressions glued together like

>> f() g()
  File "", line 1
f() g()
^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?

and it surrounds the whole expression. 

Do you have an idea on what you would prefer here? Otherwise, I suggest to 
close as "not a bug".

--

___
Python tracker 

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



[issue45801] Incorrect "Perhaps you forgot a comma" hint

2021-11-13 Thread Andre Roberge


New submission from Andre Roberge :

Python 3.10 and 3.11:

>>> sum[i for i in [1, 2, 3] if i%2==0]
  File "", line 1
sum[i for i in [1, 2, 3] if i%2==0]
^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?

Furthermore, I don't find that highlighting the entire statement (or parts of 
it, if we use print(sum[...]) is very useful in attempting to find the source 
of the error.

In previous versions, we would get the following:

>>> sum[i for i in [1, 2, 3] if i%2==0]
  File "", line 1
sum[i for i in [1, 2, 3] if i%2==0]
  ^
SyntaxError: invalid syntax

--
components: Parser
messages: 406287
nosy: aroberge, lys.nikolaou, pablogsal
priority: normal
severity: normal
status: open
title: Incorrect "Perhaps you forgot a comma" hint
versions: Python 3.10, Python 3.11

___
Python tracker 

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