default.py 文件源码

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

项目:interface 作者: ssanderson 项目源码 文件源码
def accessed_attributes_of_local(f, local_name):
        """
        Get a list of attributes of ``local_name`` accessed by ``f``.

        The analysis performed by this function is conservative, meaning that
        it's not guaranteed to find **all** attributes used.
        """
        used = set()
        # Find sequences of the form: LOAD_FAST(local_name), LOAD_ATTR(<name>).
        # This will find all usages of the form ``local_name.<name>``.
        #
        # It will **NOT** find usages in which ``local_name`` is aliased to
        # another name.
        for first, second in sliding_window(dis.get_instructions(f), 2):
            if first.opname == 'LOAD_FAST' and first.argval == local_name:
                if second.opname in ('LOAD_ATTR', 'STORE_ATTR'):
                    used.add(second.argval)
        return used
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号