eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleChecker.py

changeset 8243
cc717c2ae956
parent 8218
7c09585bd960
child 8244
ed8cb108b27b
equal deleted inserted replaced
8242:aa713ac50c0d 8243:cc717c2ae956
9 9
10 import queue 10 import queue
11 import ast 11 import ast
12 import sys 12 import sys
13 import multiprocessing 13 import multiprocessing
14 import contextlib
14 15
15 import pycodestyle 16 import pycodestyle
16 from Naming.NamingStyleChecker import NamingStyleChecker 17 from Naming.NamingStyleChecker import NamingStyleChecker
17 18
18 # register the name checker 19 # register the name checker
285 @rtype tuple of (dict, dict, None) or tuple of (None, None, ast.Module) 286 @rtype tuple of (dict, dict, None) or tuple of (None, None, ast.Module)
286 """ 287 """
287 src = "".join(source) 288 src = "".join(source)
288 289
289 try: 290 try:
290 tree = ast.parse(src, filename, 'exec') 291 if sys.version_info >= (3, 8):
292 # need the 'type_comments' parameter to include type annotations
293 tree = ast.parse(src, filename, 'exec', type_comments=True)
294 else:
295 tree = ast.parse(src, filename, 'exec')
291 return None, None, tree 296 return None, None, tree
292 except (SyntaxError, TypeError): 297 except (SyntaxError, TypeError):
293 exc_type, exc = sys.exc_info()[:2] 298 exc_type, exc = sys.exc_info()[:2]
294 if len(exc.args) > 1: 299 if len(exc.args) > 1:
295 offset = exc.args[1] 300 offset = exc.args[1]
477 }) 482 })
478 483
479 if source: 484 if source:
480 code = error["code"] 485 code = error["code"]
481 lineFlags = extractLineFlags(source[lineno - 1].strip()) 486 lineFlags = extractLineFlags(source[lineno - 1].strip())
482 try: 487 with contextlib.suppress(IndexError):
483 lineFlags += extractLineFlags(source[lineno].strip(), 488 lineFlags += extractLineFlags(source[lineno].strip(),
484 flagsLine=True) 489 flagsLine=True)
485 except IndexError:
486 pass
487 490
488 if securityOk(code, lineFlags): 491 if securityOk(code, lineFlags):
489 error["securityOk"] = True 492 error["securityOk"] = True
490 493
491 if ignoreCode(code, lineFlags): 494 if ignoreCode(code, lineFlags):

eric ide

mercurial