[New-bugs-announce] [issue42918] Nested multi-line expression will lead to "compile()" fails
Xinmeng Xia
report at bugs.python.org
Wed Jan 13 01:01:57 EST 2021
New submission from Xinmeng Xia <xiaxm at smail.nju.edu.cn>:
For build-in function compile() in mode 'single', only single statement can be well compiled. If we compile multiple statements, the parser will raise a syntaxError. Seeing the following two programs, In program 1, 2 statement are compiled. So the parser raises a Syntax error. It's the expected output. However, if we insert a nested multi-line assignment in this code(see program 2), 3 statements are compiled. We expect the parser also raise a Sytax error. But it' not.
Program 1 ( with expected results)
===================================
code1 = """
a = 1
b = 2
"""
c = compile(code1, "", "single")
===================================
Traceback (most recent call last):
File "/home/xxm/Desktop/nameChanging/report/test1.py", line 641, in <module>
c = compile(code1, "", "single")
File "", line 2
a = 1
^
SyntaxError: multiple statements found while compiling a single statement
Program 2 (with unexpected results)
=================================
code2 = """
c ='''
d=1
'''
a = 1
b = 2
"""
c = compile(code2, "", "single")
=================================
Expected out for program 2: Raise a syntaxError too, But it's not.
>> python -V
Python 3.10.0a2
>>uname -a
Linux xxm-System-Product-Name 4.15.0-64-generic #73~16.04.1-Ubuntu SMP Fri Sep 13 09:56:18 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
----------
messages: 384995
nosy: xxm
priority: normal
severity: normal
status: open
title: Nested multi-line expression will lead to "compile()" fails
type: compile error
versions: Python 3.10
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42918>
_______________________________________
More information about the New-bugs-announce
mailing list