UtilitiesPython2/pep8.py

changeset 3210
8f4fe6f76729
parent 3160
209a07d7e401
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
89 REPORT_FORMAT = { 90 REPORT_FORMAT = {
90 'default': '%(path)s:%(row)d:%(col)d: %(code)s %(text)s', 91 'default': '%(path)s:%(row)d:%(col)d: %(code)s %(text)s',
91 'pylint': '%(path)s:%(row)d: [%(code)s] %(text)s', 92 'pylint': '%(path)s:%(row)d: [%(code)s] %(text)s',
92 } 93 }
93 94
94 PyCF_ONLY_AST = 1024
95 SINGLETONS = frozenset(['False', 'None', 'True']) 95 SINGLETONS = frozenset(['False', 'None', 'True'])
96 KEYWORDS = frozenset(keyword.kwlist + ['print']) - SINGLETONS 96 KEYWORDS = frozenset(keyword.kwlist + ['print']) - SINGLETONS
97 UNARY_OPERATORS = frozenset(['>>', '**', '*', '+', '-']) 97 UNARY_OPERATORS = frozenset(['>>', '**', '*', '+', '-'])
98 ARITHMETIC_OP = frozenset(['**', '*', '/', '//', '+', '-']) 98 ARITHMETIC_OP = frozenset(['**', '*', '/', '//', '+', '-'])
99 WS_OPTIONAL_OPERATORS = ARITHMETIC_OP.union(['^', '&', '|', '<<', '>>', '%']) 99 WS_OPTIONAL_OPERATORS = ARITHMETIC_OP.union(['^', '&', '|', '<<', '>>', '%'])
1349 *args) 1349 *args)
1350 self.previous_logical = self.logical_line 1350 self.previous_logical = self.logical_line
1351 1351
1352 def check_ast(self): 1352 def check_ast(self):
1353 try: 1353 try:
1354 tree = compile(''.join(self.lines), '', 'exec', PyCF_ONLY_AST) 1354 tree = compile(''.join(self.lines), '', 'exec', ast.PyCF_ONLY_AST)
1355 except (SyntaxError, TypeError): 1355 except (SyntaxError, TypeError):
1356 return self.report_invalid_syntax() 1356 return self.report_invalid_syntax()
1357 for name, cls, _ in self._ast_checks: 1357 for name, cls, _ in self._ast_checks:
1358 # extended API for eric5 integration 1358 # extended API for eric5 integration
1359 checker = cls(tree, self.filename, self.options) 1359 checker = cls(tree, self.filename, self.options)

eric ide

mercurial