Message384995
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 |
|
Date |
User |
Action |
Args |
2021-01-13 06:01:57 | xxm | set | recipients:
+ xxm |
2021-01-13 06:01:57 | xxm | set | messageid: <1610517717.73.0.740461753555.issue42918@roundup.psfhosted.org> |
2021-01-13 06:01:57 | xxm | link | issue42918 messages |
2021-01-13 06:01:56 | xxm | create | |
|