def compare_cst(self, node):
node_op = node.ops[0].__class__
eval_op = EVAL_COMPARE.get(node_op)
if eval_op is None:
return
if node_op in (ast.In, ast.NotIn):
left_hashable = True
right_types = ITERABLE_TYPES
else:
left_hashable = False
right_types = None
if left_hashable:
left = get_constant(node.left)
else:
left = get_literal(node.left)
if left is UNSET:
return
right = get_literal(node.comparators[0], types=right_types)
if right is UNSET:
return
if (node_op in (ast.Eq, ast.NotEq)
and ((isinstance(left, str) and isinstance(right, bytes))
or (isinstance(left, bytes) and isinstance(right, str)))):
# comparison between bytes and str can raise BytesWarning depending
# on runtime option
return
try:
result = eval_op(left, right)
except TypeError:
return
return self.new_constant(node, result)
评论列表
文章目录