Pyflakes crashes if a .py file has a wrong encoding type. For example :
$ cat test.py
# -*- coding: IBO-8859-1 -*-
print 'éééé'
$ python test.py
File "test.py", line 1
SyntaxError: encoding problem: with BOM
$ pyflakes test.py
Traceback (most recent call last):
File "/usr/bin/pyflakes", line 5, in <module>
pkg_resources.run_script('pyflakes==0.3.0', 'pyflakes')
File "/usr/lib/python2.5/site-packages/pkg_resources.py", line 448, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/usr/lib/python2.5/site-packages/pkg_resources.py", line 1166, in run_script
execfile(script_filename, namespace, namespace)
File "/usr/lib/python2.5/site-packages/pyflakes-0.3.0-py2.5.egg/EGG-INFO/scripts/pyflakes", line 4, in <module>
main()
File "/usr/lib/python2.5/site-packages/pyflakes-0.3.0-py2.5.egg/pyflakes/scripts/pyflakes.py", line 68, in main
warnings += checkPath(arg)
File "/usr/lib/python2.5/site-packages/pyflakes-0.3.0-py2.5.egg/pyflakes/scripts/pyflakes.py", line 48, in checkPath
return check(file(filename, 'U').read() + '\n', filename)
File "/usr/lib/python2.5/site-packages/pyflakes-0.3.0-py2.5.egg/pyflakes/scripts/pyflakes.py", line 25, in check
line = text.splitlines()[-1]
AttributeError: 'NoneType' object has no attribute 'splitlines'
This kind of file triggers a SyntaxError? in check method but this SyntaxError? exception has an unexpected value (value[1] == (None, 0, 0, None)), assigning None to text variable, so when you try to apply splitlines() on None value you got a oooooops.
Attached to this bugreport is a really simple patch in order to warn the user and to exit gracefully.
Best regards,
Carl Chenet
www.ohmytux.com