diff options
author | Steven Myint <git@stevenmyint.com> | 2015-07-14 07:46:40 -0700 |
---|---|---|
committer | Steven Myint <git@stevenmyint.com> | 2015-07-14 07:46:40 -0700 |
commit | 1a90865abc3de27c3a9b8375fd8c73b6d2f07b64 (patch) | |
tree | fb85e21950be46f72248873d87765c714ea837b8 | |
parent | dfafb9d8a50a4b337bee16d8568e8090d0f7a138 (diff) | |
download | pep8-1a90865abc3de27c3a9b8375fd8c73b6d2f07b64.tar.gz |
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
-rwxr-xr-x | pep8.py | 9 | ||||
-rw-r--r-- | testsuite/test_api.py | 3 |
2 files changed, 10 insertions, 2 deletions
@@ -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), |