From 1a90865abc3de27c3a9b8375fd8c73b6d2f07b64 Mon Sep 17 00:00:00 2001 From: Steven Myint Date: Tue, 14 Jul 2015 07:46:40 -0700 Subject: Support Python 3.5 This involves fixing a test and avoiding a function deprecated since Python 3.0. https://docs.python.org/dev/library/inspect.html#inspect.getargspec --- pep8.py | 9 +++++++-- testsuite/test_api.py | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pep8.py b/pep8.py index 4d993da..c67e9cd 100755 --- a/pep8.py +++ b/pep8.py @@ -1328,7 +1328,12 @@ def register_check(check, codes=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 sys.version_info[0] >= 3: + parameters = list(inspect.signature(check.__init__).parameters) + else: + parameters = inspect.getargspec(check.__init__)[0] + + if parameters[:2] == ['self', 'tree']: _add_check(check, 'tree', codes, None) @@ -1504,7 +1509,7 @@ class Checker(object): """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 341fb34..1cb0d4b 100644 --- a/testsuite/test_api.py +++ b/testsuite/test_api.py @@ -339,6 +339,9 @@ class APITestCase(unittest.TestCase): 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), -- cgit v1.2.1