diff --git a/.travis.yml b/.travis.yml index b1883254..0e17587e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ python: - 3.2 - 3.3 - 3.4 + - nightly - pypy - pypy3 install: diff --git a/pep8.py b/pep8.py index 4d993dab..34ce07ae 100755 --- a/pep8.py +++ b/pep8.py @@ -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): @@ -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) @@ -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) diff --git a/testsuite/test_api.py b/testsuite/test_api.py index 341fb34b..1cb0d4b5 100644 --- a/testsuite/test_api.py +++ b/testsuite/test_api.py @@ -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),