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: Created Oct. 5, 2017, 9:41 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') | flake8-eyeo/tests/A103.py » ('J')
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 29 matching lines...) Expand all
40 } 40 }
41 41
42 ESSENTIAL_BUILTINS = set(dir(builtins)) - {'apply', 'buffer', 'coerce', 42 ESSENTIAL_BUILTINS = set(dir(builtins)) - {'apply', 'buffer', 'coerce',
43 'intern', 'file'} 43 'intern', 'file'}
44 44
45 LEAVE_BLOCK = (ast.Return, ast.Raise, ast.Continue, ast.Break) 45 LEAVE_BLOCK = (ast.Return, ast.Raise, ast.Continue, ast.Break)
46 VOLATILE = object() 46 VOLATILE = object()
47 47
48 48
49 def evaluate(node): 49 def evaluate(node):
50 names = {'__builtins__': {'True': True, 'False': False, 'None': None}}
tlucas 2017/10/06 11:41:36 Why are these values necessary? From what i under
Sebastian Noack 2017/10/06 18:11:09 True, False and None are special. They are the onl
50 try: 51 try:
51 return eval(compile(ast.Expression(node), '', 'eval'), {}) 52 return eval(compile(ast.Expression(node), '', 'eval'), names)
52 except Exception: 53 except Exception:
53 return VOLATILE 54 return VOLATILE
54 55
55 56
56 def is_const(node): 57 def is_const(node):
57 return evaluate(node) is not VOLATILE 58 return evaluate(node) is not VOLATILE
58 59
59 60
60 def get_identifier(node): 61 def get_identifier(node):
61 if isinstance(node, ast.Name): 62 if isinstance(node, ast.Name):
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 477
477 # With flake8 3, the way the entry points are register in setup.py, 478 # With flake8 3, the way the entry points are register in setup.py,
478 # they are recognized as a group, and the name and version is detected 479 # they are recognized as a group, and the name and version is detected
479 # automatically. For compatibility with flake8 2, however, we need to 480 # automatically. For compatibility with flake8 2, however, we need to
480 # assign the name and version to each checker individually. 481 # assign the name and version to each checker individually.
481 if int(flake8.__version__.split('.')[0]) < 3: 482 if int(flake8.__version__.split('.')[0]) < 3:
482 for checker in [ASTChecker, check_non_default_encoding, 483 for checker in [ASTChecker, check_non_default_encoding,
483 check_quotes, check_redundant_parenthesis]: 484 check_quotes, check_redundant_parenthesis]:
484 checker.name = 'eyeo' 485 checker.name = 'eyeo'
485 checker.version = __version__ 486 checker.version = __version__
OLDNEW
« no previous file with comments | « no previous file | flake8-eyeo/tests/A103.py » ('j') | flake8-eyeo/tests/A103.py » ('J')

Powered by Google App Engine
This is Rietveld