Index: flake8-eyeo/flake8_eyeo.py |
=================================================================== |
--- a/flake8-eyeo/flake8_eyeo.py |
+++ b/flake8-eyeo/flake8_eyeo.py |
@@ -45,15 +45,16 @@ |
VOLATILE = object() |
-def evaluate(node): |
+def evaluate(node, namespace): |
try: |
- return eval(compile(ast.Expression(node), '', 'eval'), {}) |
+ return eval(compile(ast.Expression(node), '', 'eval'), namespace) |
except Exception: |
return VOLATILE |
def is_const(node): |
- return evaluate(node) is not VOLATILE |
+ namespace = {'__builtins__': {'True': True, 'False': False, 'None': None}} |
+ return evaluate(node, namespace) is not VOLATILE |
def get_identifier(node): |
@@ -335,8 +336,9 @@ |
def _visit_hash_keys(self, nodes, what): |
keys = [] |
+ namespace = collections.defaultdict(object, vars(builtins)) |
Vasily Kuznetsov
2017/10/11 19:29:02
This is clever!
|
for node in nodes: |
- key = evaluate(node) |
+ key = evaluate(node, namespace) |
if key is VOLATILE: |
continue |