only check the actual compile() call for a SyntaxError

This commit is contained in:
Benjamin Peterson 2009-01-04 00:39:07 +00:00
parent 85d6fb5022
commit 248fb1320a
1 changed files with 5 additions and 5 deletions

View File

@ -62,12 +62,12 @@ def checker(*suffixes, **kwds):
@checker('.py', severity=4)
def check_syntax(fn, lines):
"""Check Python examples for valid syntax."""
code = ''.join(lines)
if '\r' in code:
if os.name != 'nt':
yield 0, '\\r in code file'
code = code.replace('\r', '')
try:
code = ''.join(lines)
if '\r' in code:
if os.name != 'nt':
yield 0, '\\r in code file'
code = code.replace('\r', '')
compile(code, fn, 'exec')
except SyntaxError, err:
yield err.lineno, 'not compilable: %s' % err