Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ python:
- 3.2
- 3.3
- 3.4
- nightly
- pypy
- pypy3
install:
Expand Down
13 changes: 10 additions & 3 deletions pep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,13 @@ def _is_eol_token(token, _eol_token=_is_eol_token):
_checks = {'physical_line': {}, 'logical_line': {}, 'tree': {}}


def _get_parameters(function):
if sys.version_info >= (3, 3):
return list(inspect.signature(function).parameters)
else:
return inspect.getargspec(function)[0]


def register_check(check, codes=None):
"""Register a new check object."""
def _add_check(check, kind, codes, args):
Expand All @@ -1322,13 +1329,13 @@ def _add_check(check, kind, codes, args):
else:
_checks[kind][check] = (codes or [''], args)
if inspect.isfunction(check):
args = inspect.getargspec(check)[0]
args = _get_parameters(check)
if args and args[0] in ('physical_line', 'logical_line'):
if codes is None:
codes = ERRORCODE_REGEX.findall(check.__doc__ or '')
_add_check(check, args[0], codes, args)
elif inspect.isclass(check):
if inspect.getargspec(check.__init__)[0][:2] == ['self', 'tree']:
if _get_parameters(check.__init__)[:2] == ['self', 'tree']:
_add_check(check, 'tree', codes, None)


Expand Down Expand Up @@ -1504,7 +1511,7 @@ def check_ast(self):
"""Build the file's AST and run all AST checks."""
try:
tree = compile(''.join(self.lines), '', 'exec', PyCF_ONLY_AST)
except (SyntaxError, TypeError):
except (ValueError, SyntaxError, TypeError):
return self.report_invalid_syntax()
for name, cls, __ in self._ast_checks:
checker = cls(tree, self.filename)
Expand Down
3 changes: 3 additions & 0 deletions testsuite/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ def test_check_nullbytes(self):
if 'SyntaxError' in stdout:
# PyPy 2.2 returns a SyntaxError
expected = "stdin:1:2: E901 SyntaxError"
elif 'ValueError' in stdout:
# Python 3.5.
expected = "stdin:1:1: E901 ValueError"
else:
expected = "stdin:1:1: E901 TypeError"
self.assertTrue(stdout.startswith(expected),
Expand Down