[issue18949] codeop possible flow error

Wilberto Morales report at bugs.python.org
Fri Sep 6 22:13:09 CEST 2013


Wilberto Morales added the comment:

I can't provide a example but reading the source comments it seems wrong.

'First, check if the source consists entirely of blank lines and
comments; if so, replace it with 'pass', because the built-in
parser doesn't always do the right thing for these.'

So the way I understand this is.

pure_comments_or_blank = True

for line in source:
    line = line.strip()
    if line and line[0] != '#':
        pure_comments_or_blank = False
        break

if pure_comments_or_blank:
    if symbol != "eval":
        source = "pass"

So check that atleast one line is actual code and not comments or blank. If none is then replace it with a 'pass'

Instead the loop seems a little weird. 

for line in source.split("\n"):
    line = line.strip()
    if line and line[0] != '#':
        break               # Leave it alone
else:
    if symbol != "eval":
        source = "pass"   

If it finds a something that is not a comment in a line it breaks. But then right after the for loop it contains an else statement. I'm not even sure when this else statement is executed. I'm sorry if I'm misinterpreting this.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18949>
_______________________________________


More information about the Python-bugs-list mailing list