[issue42813] Extra spaces cause unexpected EOF error in "compile" function with mode "single"

2021-09-29 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
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



[issue42813] Extra spaces cause unexpected EOF error in "compile" function with mode "single"

2021-09-29 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:

I concur with Terry, ending a file with  *is* a syntax 
error.

--

___
Python tracker 

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



[issue42813] Extra spaces cause unexpected EOF error in "compile" function with mode "single"

2021-09-29 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
Removed message: https://bugs.python.org/msg402911

___
Python tracker 

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



[issue42813] Extra spaces cause unexpected EOF error in "compile" function with mode "single"

2021-09-29 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:

I concur

--

___
Python tracker 

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



[issue42813] Extra spaces cause unexpected EOF error in "compile" function with mode "single"

2021-09-29 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

I believe that this should be closed as not-a-bug.  Ending a file with 
 *is* a syntax error.  Previous, it was assumed that the 
problem, in retrospect, was the 'extra' indent.  But one can equally say that 
the problem is the 'missing' statement after the otherwise legitimate indent.  
Even a newline is enough to make the code legal.  The current message no longer 
guess whether there is too much or too little code.

--
nosy: +pablogsal, terry.reedy

___
Python tracker 

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



[issue42813] Extra spaces cause unexpected EOF error in "compile" function with mode "single"

2021-07-04 Thread Xinmeng Xia


Xinmeng Xia  added the comment:

Program like following reports error on CPython(master branch), however this 
program can work well on PyPy. I think this is a bug in CPython
==
string ="""
if 1:
print("hello")
"""
compile(string, "", "single")
==

Traceback (most recent call last):
  File "/home/xxm/Desktop/IFuzzer/test/test1.py", line 304, in 
compile(string, "", "single")
^
  File "", line 4

SyntaxError: unexpected EOF while parsing

--

___
Python tracker 

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



[issue42813] Extra spaces cause unexpected EOF error in "compile" function with mode "single"

2021-01-03 Thread Xinmeng Xia


New submission from Xinmeng Xia :

Running the following program will lead to an unexpected EOF error. If we 
delete the space before  triple-quotation mark("""), the error will gone. If we 
replace the content of snippet with "a = 1", the program will work well. 
However, if we replace the content of snippet with "if a:pass" in a single 
line, the program cause an error again. This is weird. 

Spaces in the end of a statement should not affect the compilation of program 
in "single" mode. Besides, the error messages are different in Python2 and 
Python3. Indentation error are reported in Python 2 for snippet" if a:pass" 
while SyntaxError are reported in Python 3. 
  
==
import math
def check_stack_size( code):
# To assert that the alleged stack size is not O(N), we
# check that it is smaller than log(N).
if isinstance(code, str):
code = compile(code, "", "single")
max_size = math.ceil(math.log(len(code.co_code)))
# self.assertLessEqual(code.co_stacksize, max_size)

def test_if_else():
snippet ="""
if x:
a
elif y:
b
else:
c 
"""
check_stack_size(snippet)

test_if_else()
=
Behavior in Python 3.10:
Traceback (most recent call last):
  File "/home/xxm/Desktop/nameChanging/report/temp.py", line 30, in 
test_if_else()
  File "/home/xxm/Desktop/nameChanging/report/temp.py", line 20, in test_if_else
check_stack_size(snippet)
  File "/home/xxm/Desktop/nameChanging/report/temp.py", line 6, in 
check_stack_size
code = compile(code, "", "single")
  File "", line 8

SyntaxError: unexpected EOF while parsing

Behaviors in Python2: 
Traceback (most recent call last):
  File "/home/xxm/Desktop/nameChanging/report/temp.py", line 30, in 
test_if_else()
  File "/home/xxm/Desktop/nameChanging/report/temp.py", line 27, in test_if_else
check_stack_size(snippet)
  File "/home/xxm/Desktop/nameChanging/report/temp.py", line 6, in 
check_stack_size
code = compile(code, "", "single")
  File "", line 3

^
IndentationError: unexpected indent

--
components: Interpreter Core
messages: 384257
nosy: xxm
priority: normal
severity: normal
status: open
title: Extra spaces cause unexpected EOF error in "compile" function with mode 
"single"
type: compile error
versions: Python 3.10

___
Python tracker 

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