You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
3.11 exec raises SystemError instead of SyntaxError on char after line continuation #89901
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2021-11-14.13:59:48.259>created_at=<Date2021-11-06.13:10:51.997>labels= ['type-bug', '3.9', '3.11']
title='3.11 exec raises SystemError instead of SyntaxError on char after line continuation'updated_at=<Date2021-11-14.18:39:21.628>user='https://github.com/pewscorner'
When exec'ing code with an illegal character after the line continuation character '\', python 3.11.0a2 raises this strange exception:
SystemError: Negative size passed to PyUnicode_New
Here's an example where '#' is the illegal character:
exec('1,\\#\n2')
I expected the following exception (which is raised by Python 3.10.0, and also by Python 3.11.0a2 when using eval instead of exec, or when the string content is put into its own file and run as a normal script):
SyntaxError: unexpected character after line continuation character
Yep, this also break IPython command completions when users press tab in some places in multiline code.
88f4ec8 is the first offending commit for me in the 3.9 branch:
[3.9] bpo-45494: Fix parser crash when reporting errors involving invalid continuation characters (GH-28993) (bpo-29071)
There are two errors that this commit fixes:
* The parser was not correctly computing the offset and the string
source for E_LINECONT errors due to the incorrect usage of strtok().
* The parser was not correctly unwinding the call stack when a tokenizer
exception happened in rules involving optionals ('?', [...]) as we
always make them return valid results by using the comma operator. We
need to check first if we don't have an error before continuing..
(cherry picked from commit a106343f632a99c8ebb0136fa140cf189b4a6a57)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
NOTE: unlike the cherry-picked original, this commit points at a crazy location
due to a bug in the tokenizer that required a big refactor in 3.10 to fix.
We are leaving as-is for 3.9.
Carreau commented on Nov 12, 2021
Carreaumannequin
Mannequin
More actions
Note that with the following example, exec and CommandCompiler return a different error:
I will be able to take a look later in the weekend, so if someone is able to give it a go before, that would be great.
Carreau commented on Nov 12, 2021
Carreaumannequin
Mannequin
More actions
I will be able to take a look later in the weekend
Please take some time for yourself, I added you as you were the original author of the patch to make you aware. I believe most projects can workaround that for now.
New changeset 25835c5 by Pablo Galindo Salgado in branch 'main': bpo-45738: Fix computation of error location for invalid continuation (GH-29550) 25835c5
New changeset bf26a6d by Miss Islington (bot) in branch '3.10': bpo-45738: Fix computation of error location for invalid continuation (GH-29550) bf26a6d
New changeset 142fcb4 by Pablo Galindo Salgado in branch '3.9': bpo-45738: Fix computation of error location for invalid continuation characters in the parser (GH-29550) (GH-29552) 142fcb4
Activity
pewscorner commentedon Nov 6, 2021
When exec'ing code with an illegal character after the line continuation character '\', python 3.11.0a2 raises this strange exception:
SystemError: Negative size passed to PyUnicode_New
Here's an example where '#' is the illegal character:
I expected the following exception (which is raised by Python 3.10.0, and also by Python 3.11.0a2 when using eval instead of exec, or when the string content is put into its own file and run as a normal script):
SyntaxError: unexpected character after line continuation character
Zac-HD commentedon Nov 12, 2021
It looks like this also affects Python 3.9.8, which makes me very suspicious of https://bugs.python.org/issue45494 as the probable cause.
See Zac-HD/hypothesmith#16 and psf/black#2592 (comment) for reports.
Carreau commentedon Nov 12, 2021
Yep, this also break IPython command completions when users press tab in some places in multiline code.
88f4ec8 is the first offending commit for me in the 3.9 branch:
Carreau commentedon Nov 12, 2021
Note that with the following example, exec and CommandCompiler return a different error:
pablogsal commentedon Nov 12, 2021
I will be able to take a look later in the weekend, so if someone is able to give it a go before, that would be great.
Carreau commentedon Nov 12, 2021
Please take some time for yourself, I added you as you were the original author of the patch to make you aware. I believe most projects can workaround that for now.
pablogsal commentedon Nov 14, 2021
New changeset 25835c5 by Pablo Galindo Salgado in branch 'main':
bpo-45738: Fix computation of error location for invalid continuation (GH-29550)
25835c5
miss-islington commentedon Nov 14, 2021
New changeset bf26a6d by Miss Islington (bot) in branch '3.10':
bpo-45738: Fix computation of error location for invalid continuation (GH-29550)
bf26a6d
pablogsal commentedon Nov 14, 2021
This should be fixed by now, but please, check if everything is in order in your respective test suites and confirm here.
pablogsal commentedon Nov 14, 2021
New changeset 142fcb4 by Pablo Galindo Salgado in branch '3.9':
bpo-45738: Fix computation of error location for invalid continuation characters in the parser (GH-29550) (GH-29552)
142fcb4
pewscorner commentedon Nov 14, 2021
Seems to work. Thanks!
Carreau commentedon Nov 14, 2021
Works for me as well. Thanks.