Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: flake8-eyeo/flake8_eyeo.py

Issue 29565854: Noissue - Improved accuracy of evaluated expressions for A103 and A207 (Closed)
Patch Set: Rebased Created Oct. 11, 2017, 6:23 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | flake8-eyeo/tests/A103.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # This file is part of Adblock Plus <https://adblockplus.org/>, 1 # This file is part of Adblock Plus <https://adblockplus.org/>,
2 # Copyright (C) 2006-present eyeo GmbH 2 # Copyright (C) 2006-present eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(...skipping 28 matching lines...) Expand all
39 } 39 }
40 40
41 ESSENTIAL_BUILTINS = set(dir(builtins)) - {'apply', 'buffer', 'coerce', 41 ESSENTIAL_BUILTINS = set(dir(builtins)) - {'apply', 'buffer', 'coerce',
42 'intern', 'file'} 42 'intern', 'file'}
43 43
44 LEAVE_BLOCK = (ast.Return, ast.Raise, ast.Continue, ast.Break) 44 LEAVE_BLOCK = (ast.Return, ast.Raise, ast.Continue, ast.Break)
45 VOLATILE = object() 45 VOLATILE = object()
46 46
47 47
48 def evaluate(node): 48 def evaluate(node):
49 names = {'__builtins__': {'True': True, 'False': False, 'None': None}}
49 try: 50 try:
50 return eval(compile(ast.Expression(node), '', 'eval'), {}) 51 return eval(compile(ast.Expression(node), '', 'eval'), names)
51 except Exception: 52 except Exception:
52 return VOLATILE 53 return VOLATILE
53 54
54 55
55 def is_const(node): 56 def is_const(node):
56 return evaluate(node) is not VOLATILE 57 return evaluate(node) is not VOLATILE
57 58
58 59
59 def get_identifier(node): 60 def get_identifier(node):
60 if isinstance(node, ast.Name): 61 if isinstance(node, ast.Name):
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 return [(pos, 'A111 redundant parenthesis for {} ' 465 return [(pos, 'A111 redundant parenthesis for {} '
465 'statement'.format(statement))] 466 'statement'.format(statement))]
466 467
467 return [] 468 return []
468 469
469 470
470 for checker in [check_ast, check_non_default_encoding, 471 for checker in [check_ast, check_non_default_encoding,
471 check_quotes, check_redundant_parenthesis]: 472 check_quotes, check_redundant_parenthesis]:
472 checker.name = 'eyeo' 473 checker.name = 'eyeo'
473 checker.version = __version__ 474 checker.version = __version__
OLDNEW
« no previous file with comments | « no previous file | flake8-eyeo/tests/A103.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld