@@ -1314,6 +1314,13 @@ def _is_eol_token(token, _eol_token=_is_eol_token):
1314
1314
_checks = {'physical_line' : {}, 'logical_line' : {}, 'tree' : {}}
1315
1315
1316
1316
1317
+ def _get_parameters (function ):
1318
+ if sys .version_info >= (3 , 3 ):
1319
+ return list (inspect .signature (function ).parameters )
1320
+ else :
1321
+ return inspect .getargspec (function )[0 ]
1322
+
1323
+
1317
1324
def register_check (check , codes = None ):
1318
1325
"""Register a new check object."""
1319
1326
def _add_check (check , kind , codes , args ):
@@ -1322,13 +1329,13 @@ def _add_check(check, kind, codes, args):
1322
1329
else :
1323
1330
_checks [kind ][check ] = (codes or ['' ], args )
1324
1331
if inspect .isfunction (check ):
1325
- args = inspect . getargspec (check )[ 0 ]
1332
+ args = _get_parameters (check )
1326
1333
if args and args [0 ] in ('physical_line' , 'logical_line' ):
1327
1334
if codes is None :
1328
1335
codes = ERRORCODE_REGEX .findall (check .__doc__ or '' )
1329
1336
_add_check (check , args [0 ], codes , args )
1330
1337
elif inspect .isclass (check ):
1331
- if inspect . getargspec (check .__init__ )[ 0 ] [:2 ] == ['self' , 'tree' ]:
1338
+ if _get_parameters (check .__init__ )[:2 ] == ['self' , 'tree' ]:
1332
1339
_add_check (check , 'tree' , codes , None )
1333
1340
1334
1341
@@ -1504,7 +1511,7 @@ def check_ast(self):
1504
1511
"""Build the file's AST and run all AST checks."""
1505
1512
try :
1506
1513
tree = compile ('' .join (self .lines ), '' , 'exec' , PyCF_ONLY_AST )
1507
- except (SyntaxError , TypeError ):
1514
+ except (ValueError , SyntaxError , TypeError ):
1508
1515
return self .report_invalid_syntax ()
1509
1516
for name , cls , __ in self ._ast_checks :
1510
1517
checker = cls (tree , self .filename )
0 commit comments