python类IfExp()的实例源码

simple_instructions.py 文件源码 项目:femtocode 作者: diana-hep 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def process_ifexpr(self, node):

        if isinstance(node, _ast.If):
            test = node.test
            then = node.body
            else_ = node.orelse

            assert len(then) == 1
            then = then[0]

            assert len(else_) == 1

            else_ = else_[0]

            if_exp = _ast.IfExp(test, then, else_, lineno=node.lineno, col_offset=0)
            return if_exp
        else:
            return node
checker.py 文件源码 项目:sublimeTextConfig 作者: luoye-fe 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def handleNodeDelete(self, node):

        def on_conditional_branch():
            """
            Return `True` if node is part of a conditional body.
            """
            current = getattr(node, 'parent', None)
            while current:
                if isinstance(current, (ast.If, ast.While, ast.IfExp)):
                    return True
                current = getattr(current, 'parent', None)
            return False

        name = getNodeName(node)
        if not name:
            return

        if on_conditional_branch():
            # We cannot predict if this conditional branch is going to
            # be executed.
            return

        if isinstance(self.scope, FunctionScope) and name in self.scope.globals:
            self.scope.globals.remove(name)
        else:
            try:
                del self.scope[name]
            except KeyError:
                self.report(messages.UndefinedName, node, name)
checker.py 文件源码 项目:blackmamba 作者: zrzka 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def handleNodeDelete(self, node):

        def on_conditional_branch():
            """
            Return `True` if node is part of a conditional body.
            """
            current = getattr(node, 'parent', None)
            while current:
                if isinstance(current, (ast.If, ast.While, ast.IfExp)):
                    return True
                current = getattr(current, 'parent', None)
            return False

        name = getNodeName(node)
        if not name:
            return

        if on_conditional_branch():
            # We cannot predict if this conditional branch is going to
            # be executed.
            return

        if isinstance(self.scope, FunctionScope) and name in self.scope.globals:
            self.scope.globals.remove(name)
        else:
            try:
                del self.scope[name]
            except KeyError:
                self.report(messages.UndefinedName, node, name)
overpassify.py 文件源码 项目:overpassify 作者: gappleto97 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _(assignment, **kwargs):
    if isinstance(assignment.value, (_ast.IfExp)):
        return parse(assignment.value, name=assignment.targets[0])
    else:
        return '({};) -> {};'.format(
            parse(assignment.value),
            parse(assignment.targets[0])
        )
checker.py 文件源码 项目:wuye.vim 作者: zhaoyingnan911 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def handleNodeDelete(self, node):

        def on_conditional_branch():
            """
            Return `True` if node is part of a conditional body.
            """
            current = getattr(node, 'parent', None)
            while current:
                if isinstance(current, (ast.If, ast.While, ast.IfExp)):
                    return True
                current = getattr(current, 'parent', None)
            return False

        name = getNodeName(node)
        if not name:
            return

        if on_conditional_branch():
            # We can not predict if this conditional branch is going to
            # be executed.
            return

        if isinstance(self.scope, FunctionScope) and name in self.scope.globals:
            self.scope.globals.remove(name)
        else:
            try:
                del self.scope[name]
            except KeyError:
                self.report(messages.UndefinedName, node, name)


问题


面经


文章

微信
公众号

扫码关注公众号