summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2012-06-26 21:48:11 +0200
committerFlorent Xicluna <florent.xicluna@gmail.com>2012-06-26 21:48:11 +0200
commited51a8381f0f758a9345cccd486f8aa8f1229b08 (patch)
treed0ee1523934ff115e13499c1aa5c7b0a4757c557
parent4a09ae744198adcaeeb5291e179935811dffc279 (diff)
downloadpep8-ed51a8381f0f758a9345cccd486f8aa8f1229b08.tar.gz
Add E902 errors for IOErrors; issue #87.
-rw-r--r--CHANGES.txt2
-rwxr-xr-xpep8.py15
2 files changed, 13 insertions, 4 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index e7a5e8e..6832f09 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -8,6 +8,8 @@ Changelog
* Revert to the previous behaviour for ``--show-pep8``:
do not imply ``--first``. (Issue #89)
+* Add E902 for IO errors. (Issue #87)
+
* Fix false positive for E121, and missed E124. (Issue #92)
* Set a sensible default path for config file on Windows. (Issue #95)
diff --git a/pep8.py b/pep8.py
index ef5c477..d3507bb 100755
--- a/pep8.py
+++ b/pep8.py
@@ -1051,6 +1051,7 @@ else:
isidentifier = str.isidentifier
stdin_get_value = TextIOWrapper(sys.stdin.buffer, errors='ignore').read
+readlines.__doc__ = " Read the source code."
def expand_indent(line):
@@ -1164,6 +1165,7 @@ class Checker(object):
options = StyleGuide(kwargs).options
else:
assert not kwargs
+ self._io_error = None
self._physical_checks = options.physical_checks
self._logical_checks = options.logical_checks
self.max_line_length = options.max_line_length
@@ -1173,7 +1175,12 @@ class Checker(object):
self.filename = 'stdin'
self.lines = lines or []
elif lines is None:
- self.lines = readlines(filename)
+ try:
+ self.lines = readlines(filename)
+ except IOError:
+ exc_type, exc = sys.exc_info()[:2]
+ self._io_error = '%s: %s' % (exc_type.__name__, exc)
+ self.lines = []
else:
self.lines = lines
self.report = report or options.report
@@ -1282,9 +1289,8 @@ class Checker(object):
self.previous_logical = self.logical_line
def generate_tokens(self):
- """
- Check if the syntax is valid.
- """
+ if self._io_error:
+ self.report_error(1, 0, 'E902 %s' % self._io_error, readlines)
tokengen = tokenize.generate_tokens(self.readline_check_physical)
try:
for token in tokengen:
@@ -1297,6 +1303,7 @@ class Checker(object):
self.report_error(offset[0], offset[1],
'E901 %s: %s' % (exc_type.__name__, exc.args[0]),
self.generate_tokens)
+ generate_tokens.__doc__ = " Check if the syntax is valid."
def check_all(self, expected=None, line_offset=0):
"""