def optimize_iterable(self, node):
# it's already a constant, nothing to do
if isinstance(node, ast.Constant):
return
# remplace empty dict (create at runtime) with an empty tuple
# (constant)
if isinstance(node, ast.Dict) and not node.keys:
return self.new_constant(node, ())
# FIXME: optimize dict?
value = get_literal(node, types=(list, set), constant_items=True)
if value is UNSET:
return
if not value:
# replace empty iterable with an empty tuple
return self.new_constant(node, ())
if len(value) > self.config.max_seq_len:
return
if isinstance(value, list):
return self.new_constant(node, tuple(value))
if isinstance(value, set):
return self.new_constant(node, frozenset(value))
评论列表
文章目录