Skip to content

Commit 1a90865

Browse files
committed
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
1 parent dfafb9d commit 1a90865

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

pep8.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,12 @@ def _add_check(check, kind, codes, args):
13281328
codes = ERRORCODE_REGEX.findall(check.__doc__ or '')
13291329
_add_check(check, args[0], codes, args)
13301330
elif inspect.isclass(check):
1331-
if inspect.getargspec(check.__init__)[0][:2] == ['self', 'tree']:
1331+
if sys.version_info[0] >= 3:
1332+
parameters = list(inspect.signature(check.__init__).parameters)
1333+
else:
1334+
parameters = inspect.getargspec(check.__init__)[0]
1335+
1336+
if parameters[:2] == ['self', 'tree']:
13321337
_add_check(check, 'tree', codes, None)
13331338

13341339

@@ -1504,7 +1509,7 @@ def check_ast(self):
15041509
"""Build the file's AST and run all AST checks."""
15051510
try:
15061511
tree = compile(''.join(self.lines), '', 'exec', PyCF_ONLY_AST)
1507-
except (SyntaxError, TypeError):
1512+
except (ValueError, SyntaxError, TypeError):
15081513
return self.report_invalid_syntax()
15091514
for name, cls, __ in self._ast_checks:
15101515
checker = cls(tree, self.filename)

testsuite/test_api.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@ def test_check_nullbytes(self):
339339
if 'SyntaxError' in stdout:
340340
# PyPy 2.2 returns a SyntaxError
341341
expected = "stdin:1:2: E901 SyntaxError"
342+
elif 'ValueError' in stdout:
343+
# Python 3.5.
344+
expected = "stdin:1:1: E901 ValueError"
342345
else:
343346
expected = "stdin:1:1: E901 TypeError"
344347
self.assertTrue(stdout.startswith(expected),

0 commit comments

Comments
 (0)