Plugins/CheckerPlugins/CodeStyleChecker/pep8.py

changeset 3210
8f4fe6f76729
parent 3160
209a07d7e401
child 3484
645c12de6b0c
equal deleted inserted replaced
3208:884465a61753 3210:8f4fe6f76729
66 import re 66 import re
67 import time 67 import time
68 import inspect 68 import inspect
69 import keyword 69 import keyword
70 import tokenize 70 import tokenize
71 import ast
71 from optparse import OptionParser 72 from optparse import OptionParser
72 from fnmatch import fnmatch 73 from fnmatch import fnmatch
73 try: 74 try:
74 from configparser import RawConfigParser 75 from configparser import RawConfigParser
75 from io import TextIOWrapper 76 from io import TextIOWrapper
91 REPORT_FORMAT = { 92 REPORT_FORMAT = {
92 'default': '%(path)s:%(row)d:%(col)d: %(code)s %(text)s', 93 'default': '%(path)s:%(row)d:%(col)d: %(code)s %(text)s',
93 'pylint': '%(path)s:%(row)d: [%(code)s] %(text)s', 94 'pylint': '%(path)s:%(row)d: [%(code)s] %(text)s',
94 } 95 }
95 96
96 PyCF_ONLY_AST = 1024
97 SINGLETONS = frozenset(['False', 'None', 'True']) 97 SINGLETONS = frozenset(['False', 'None', 'True'])
98 KEYWORDS = frozenset(keyword.kwlist + ['print']) - SINGLETONS 98 KEYWORDS = frozenset(keyword.kwlist + ['print']) - SINGLETONS
99 UNARY_OPERATORS = frozenset(['>>', '**', '*', '+', '-']) 99 UNARY_OPERATORS = frozenset(['>>', '**', '*', '+', '-'])
100 ARITHMETIC_OP = frozenset(['**', '*', '/', '//', '+', '-']) 100 ARITHMETIC_OP = frozenset(['**', '*', '/', '//', '+', '-'])
101 WS_OPTIONAL_OPERATORS = ARITHMETIC_OP.union(['^', '&', '|', '<<', '>>', '%']) 101 WS_OPTIONAL_OPERATORS = ARITHMETIC_OP.union(['^', '&', '|', '<<', '>>', '%'])
1507 *args) 1507 *args)
1508 self.previous_logical = self.logical_line 1508 self.previous_logical = self.logical_line
1509 1509
1510 def check_ast(self): 1510 def check_ast(self):
1511 try: 1511 try:
1512 tree = compile(''.join(self.lines), '', 'exec', PyCF_ONLY_AST) 1512 tree = compile(''.join(self.lines), '', 'exec', ast.PyCF_ONLY_AST)
1513 except (SyntaxError, TypeError): 1513 except (SyntaxError, TypeError):
1514 return self.report_invalid_syntax() 1514 return self.report_invalid_syntax()
1515 for name, cls, _ in self._ast_checks: 1515 for name, cls, _ in self._ast_checks:
1516 # extended API for eric5 integration 1516 # extended API for eric5 integration
1517 checker = cls(tree, self.filename, self.options) 1517 checker = cls(tree, self.filename, self.options)

eric ide

mercurial