Close file stream in qute_pylint.modeline

This commit is contained in:
Florian Bruhin 2016-07-23 17:00:05 +02:00
parent 3d4a01ef4c
commit 04fdce9058

View File

@ -19,6 +19,7 @@
"""Checker for vim modelines in files.""" """Checker for vim modelines in files."""
import os.path import os.path
import contextlib
from pylint import interfaces, checkers from pylint import interfaces, checkers
@ -41,15 +42,16 @@ class ModelineChecker(checkers.BaseChecker):
if os.path.basename(os.path.splitext(node.file)[0]) == '__init__': if os.path.basename(os.path.splitext(node.file)[0]) == '__init__':
return return
max_lineno = 1 max_lineno = 1
for (lineno, line) in enumerate(node.file_stream): with contextlib.closing(node.stream()) as stream:
for (lineno, line) in enumerate(stream):
if lineno == 1 and line.startswith(b'#!'): if lineno == 1 and line.startswith(b'#!'):
max_lineno += 1 max_lineno += 1
continue continue
elif line.startswith(b'# vim:'): elif line.startswith(b'# vim:'):
if lineno > max_lineno: if lineno > max_lineno:
self.add_message('modeline-position', line=lineno) self.add_message('modeline-position', line=lineno)
if (line.rstrip() != if (line.rstrip() != b'# vim: ft=python '
b'# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:'): b'fileencoding=utf-8 sts=4 sw=4 et:'):
self.add_message('invalid-modeline', line=lineno) self.add_message('invalid-modeline', line=lineno)
break break
else: else: