iterable.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:fatoptimizer 作者: vstinner 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号