summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Myint <git@stevenmyint.com>2015-07-14 07:46:40 -0700
committerSteven Myint <git@stevenmyint.com>2015-07-14 07:46:40 -0700
commit1a90865abc3de27c3a9b8375fd8c73b6d2f07b64 (patch)
treefb85e21950be46f72248873d87765c714ea837b8
parentdfafb9d8a50a4b337bee16d8568e8090d0f7a138 (diff)
downloadpep8-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-xpep8.py9
-rw-r--r--testsuite/test_api.py3
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),