-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
Nested multi-line expression will lead to "compile()" fails #87084
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
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.
|
What does the bytecode for c in program 2 look like? Also, how do you find all these bugs? Are you developing a new fuzzier? |
The bytecode of c is as following:
=============================================== Yes, my team is working on developing a new fuzzier for the CPython. Also, we are trying to apply it on the newest version of CPython. We will carefully analyze all bugs before reporting them on the tracker. Hope our work does not bother you too much. |
It’s good work! Is it open source? |
For sure! As soon as we validate this technique, we will open source it on GitHub. |
Thanks a lot for the report, Xinmeng! This is a bug in how we're checking for bad single statements in bad_single_statement and it's not trivial to fix due to the string shenanigans we're doing there in newline_in_string, which does not account for many edge cases. I'll try to dig a bit deeper during the weekend. |
Thanks! ✨ 🍰 ✨ |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: