Skip to content
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

code.runsource() parsing bug #50729

Closed
smcallis mannequin opened this issue Jul 14, 2009 · 3 comments
Closed

code.runsource() parsing bug #50729

smcallis mannequin opened this issue Jul 14, 2009 · 3 comments

Comments

@smcallis
Copy link
Mannequin

smcallis mannequin commented Jul 14, 2009

BPO 6480
Nosy @birkenfeld

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 = None
closed_at = <Date 2010-07-29.17:03:46.873>
created_at = <Date 2009-07-14.05:19:56.396>
labels = ['invalid']
title = 'code.runsource() parsing bug'
updated_at = <Date 2010-07-29.17:03:46.843>
user = 'https://bugs.python.org/smcallis'

bugs.python.org fields:

activity = <Date 2010-07-29.17:03:46.843>
actor = 'georg.brandl'
assignee = 'none'
closed = True
closed_date = <Date 2010-07-29.17:03:46.873>
closer = 'georg.brandl'
components = ['None']
creation = <Date 2009-07-14.05:19:56.396>
creator = 'smcallis'
dependencies = []
files = []
hgrepos = []
issue_num = 6480
keywords = []
message_count = 3.0
messages = ['90511', '90520', '111968']
nosy_count = 2.0
nosy_names = ['georg.brandl', 'smcallis']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue6480'
versions = ['Python 2.6']

@smcallis
Copy link
Mannequin Author

smcallis mannequin commented Jul 14, 2009

I'm writing a little pre-processor that just parses python snippets out
of a file and passes them to a code.InteractiveInterpreter, and I'm
noticing some somewhat nasty stuff in how runsource handles some code.

sys.version:
'2.6.2 (r262:71600, Jul 12 2009, 11:52:33) \n[GCC 4.0.1 (Apple Inc.
build 5465)]'

Doesn't work:
interpreter.runsource('print("Foo")\nprint "Bar"')

Works:
interpreter.runsource('print("Foo");print "Bar"')

Doesn't work:
interpreter.runsource('print("Foo");\nprint "Bar"')

Exact output:
>>> interpreter.runsource('print("Foo")\nprint "Bar"')                 
                                            
Foo                                                                    
                                            
False                                                                  
                                            
>>> interpreter.runsource('print("Foo");print "Bar"')                  
                                            
Foo                                                                    
                                            
Bar                                                                    
                                            
False                                                                  
                                            
>>> interpreter.runsource('print("Foo");\nprint "Bar"')                
                                            
Foo                                                                    
                                            
False                                                                  
                                            
>>>     

Is this a known issue? I didn't see it while searching the bug database...

@smcallis
Copy link
Mannequin Author

smcallis mannequin commented Jul 14, 2009

Seems to me it's probably an issue with the newlines, but from
help(code.compile_command):

Compile a command and determine whether it is incomplete.

Arguments:

source -- the source string; <b>may contain \n characters</b>
filename -- optional filename from which source was read; default
            "<input>"
symbol -- optional grammar start symbol; "single" (default) or

@birkenfeld
Copy link
Member

code.runsource() uses the "single" start symbol by default, which will parse only a single statement. Only your second snippet is a single statement, while the others are two statements.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant