@@ -1314,6 +1314,13 @@ def _is_eol_token(token, _eol_token=_is_eol_token):
13141314_checks = {'physical_line' : {}, 'logical_line' : {}, 'tree' : {}}
13151315
13161316
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+
13171324def register_check (check , codes = None ):
13181325 """Register a new check object."""
13191326 def _add_check (check , kind , codes , args ):
@@ -1322,13 +1329,13 @@ def _add_check(check, kind, codes, args):
13221329 else :
13231330 _checks [kind ][check ] = (codes or ['' ], args )
13241331 if inspect .isfunction (check ):
1325- args = inspect . getargspec (check )[ 0 ]
1332+ args = _get_parameters (check )
13261333 if args and args [0 ] in ('physical_line' , 'logical_line' ):
13271334 if codes is None :
13281335 codes = ERRORCODE_REGEX .findall (check .__doc__ or '' )
13291336 _add_check (check , args [0 ], codes , args )
13301337 elif inspect .isclass (check ):
1331- if inspect . getargspec (check .__init__ )[ 0 ] [:2 ] == ['self' , 'tree' ]:
1338+ if _get_parameters (check .__init__ )[:2 ] == ['self' , 'tree' ]:
13321339 _add_check (check , 'tree' , codes , None )
13331340
13341341
@@ -1504,7 +1511,7 @@ def check_ast(self):
15041511 """Build the file's AST and run all AST checks."""
15051512 try :
15061513 tree = compile ('' .join (self .lines ), '' , 'exec' , PyCF_ONLY_AST )
1507- except (SyntaxError , TypeError ):
1514+ except (ValueError , SyntaxError , TypeError ):
15081515 return self .report_invalid_syntax ()
15091516 for name , cls , __ in self ._ast_checks :
15101517 checker = cls (tree , self .filename )
0 commit comments