当前位置: 首页>>代码示例>>Python>>正文


Python astroid.parse方法代码示例

本文整理汇总了Python中astroid.parse方法的典型用法代码示例。如果您正苦于以下问题:Python astroid.parse方法的具体用法?Python astroid.parse怎么用?Python astroid.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在astroid的用法示例。


在下文中一共展示了astroid.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _re_transform

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import parse [as 别名]
def _re_transform():
        return astroid.parse('''
        import sre_compile
        ASCII = sre_compile.SRE_FLAG_ASCII
        IGNORECASE = sre_compile.SRE_FLAG_IGNORECASE
        LOCALE = sre_compile.SRE_FLAG_LOCALE
        UNICODE = sre_compile.SRE_FLAG_UNICODE
        MULTILINE = sre_compile.SRE_FLAG_MULTILINE
        DOTALL = sre_compile.SRE_FLAG_DOTALL
        VERBOSE = sre_compile.SRE_FLAG_VERBOSE
        A = ASCII
        I = IGNORECASE
        L = LOCALE
        U = UNICODE
        M = MULTILINE
        S = DOTALL
        X = VERBOSE
        TEMPLATE = sre_compile.SRE_FLAG_TEMPLATE
        T = TEMPLATE
        DEBUG = sre_compile.SRE_FLAG_DEBUG
        ''') 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:23,代码来源:brain_re.py

示例2: test_message_simple

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import parse [as 别名]
def test_message_simple(self):
        src = """
        x = 10
        x = 230
        print(x)
        """
        mod = astroid.parse(src)
        mod.accept(CFGVisitor())
        assign_1, _ = mod.nodes_of_class(astroid.Assign)

        self.checker.visit_module(mod)
        with self.assertAddsMessages(
            pylint.testutils.Message(
                msg_id='redundant-assignment',
                node=assign_1,
            ),
        ):
            self.checker.visit_assign(assign_1) 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:20,代码来源:test_redundant_assignment_checker.py

示例3: test_message_if_stmt

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import parse [as 别名]
def test_message_if_stmt(self):
        src = """
        x = 10
        y = 5
        if y > 5:
            x = 20
        else:
            x = 15
        print(x)
            
        """
        mod = astroid.parse(src)
        mod.accept(CFGVisitor())
        assign_x, *_ = mod.nodes_of_class(astroid.Assign)

        self.checker.visit_module(mod)
        with self.assertAddsMessages(
            pylint.testutils.Message(
                msg_id='redundant-assignment',
                node=assign_x,
            ),
        ):
            self.checker.visit_assign(assign_x) 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:25,代码来源:test_redundant_assignment_checker.py

示例4: test_message_scope

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import parse [as 别名]
def test_message_scope(self):
        src = """
        x = 25
        def func():
            def func2():
                print(x - 1)
            func2()
        x = 10
        func()
        """
        mod = astroid.parse(src)
        mod.accept(CFGVisitor())
        assign_x, *_ = mod.nodes_of_class(astroid.Assign)

        self.checker.visit_module(mod)
        with self.assertAddsMessages(
                pylint.testutils.Message(
                    msg_id='redundant-assignment',
                    node=assign_x,
                )
        ):
            self.checker.visit_assign(assign_x) 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:24,代码来源:test_redundant_assignment_checker.py

示例5: test_no_message_loop_complex

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import parse [as 别名]
def test_no_message_loop_complex(self):
        src = """
        x = 10
        for y in range(1, 10):
            x = func(y)
            print(x)
        x = x - 1
        """
        mod = astroid.parse(src)
        mod.accept(CFGVisitor())
        assign_x1, assign_x2, assign_x3 = mod.nodes_of_class(astroid.Assign)

        self.checker.visit_module(mod)
        with self.assertNoMessages():
            self.checker.visit_assign(assign_x1)
            self.checker.visit_assign(assign_x2)
            self.checker.visit_assign(assign_x3) 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:19,代码来源:test_redundant_assignment_checker.py

示例6: test_no_message_if_complex

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import parse [as 别名]
def test_no_message_if_complex(self):
        src = """
        x = 10
        y = 5
        if y > 5:
            x = 20
        elif y > 50:
            x = 15
        else:
            pass
        print(x)
        """
        mod = astroid.parse(src)
        mod.accept(CFGVisitor())
        assign_x, *_ = mod.nodes_of_class(astroid.Assign)

        self.checker.visit_module(mod)
        with self.assertNoMessages():
            self.checker.visit_assign(assign_x) 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:21,代码来源:test_redundant_assignment_checker.py

示例7: test_no_message_function_def

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import parse [as 别名]
def test_no_message_function_def(self):
        src = """
        x = 10
        if False:
            x = 20
        else:
            def func():
                x = 1
        print(x)
        """
        mod = astroid.parse(src)
        mod.accept(CFGVisitor())
        assign_x, *_ = mod.nodes_of_class(astroid.Assign)

        self.checker.visit_module(mod)
        with self.assertNoMessages():
            self.checker.visit_assign(assign_x) 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:19,代码来源:test_redundant_assignment_checker.py

示例8: test_augassign_multiple_no_message

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import parse [as 别名]
def test_augassign_multiple_no_message(self):
        src = """
        y_pos = 5
        y_pos += 10
        y_pos += 10
        y_pos += 10
        y_pos += 10
        """
        mod = astroid.parse(src)
        mod.accept(CFGVisitor())

        self.checker.visit_module(mod)
        with self.assertNoMessages():
            for node in mod.nodes_of_class(astroid.Assign):
                self.checker.visit_assign(node)
            for node in mod.nodes_of_class(astroid.AugAssign):
                self.checker.visit_augassign(node) 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:19,代码来源:test_redundant_assignment_checker.py

示例9: test_no_messages_simple

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import parse [as 别名]
def test_no_messages_simple(self):
        src = """
        def test(x):
            x = 10
            if True:
                return x
            return x
        """
        mod = astroid.parse(src)
        mod.accept(CFGVisitor())
        func_node = mod.body[0]
        name_node_a, name_node_b = mod.nodes_of_class(astroid.Name)

        with self.assertNoMessages():
            self.checker.visit_module(mod)
            self.checker.visit_functiondef(func_node)
            self.checker.visit_name(name_node_a)
            self.checker.visit_name(name_node_b) 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:20,代码来源:test_possibly_undefined_checker.py

示例10: test_no_messages_with_import

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import parse [as 别名]
def test_no_messages_with_import(self):
        src = """
        import j

        y = 0
        if y > 10:
            j = 10
        else:
            y = 5
        print(j)
        """
        mod = astroid.parse(src)
        mod.accept(CFGVisitor())
        name_node_y, name_node_print, name_node_j = mod.nodes_of_class(
            astroid.Name)
        with self.assertNoMessages():
            self.checker.visit_module(mod)
            self.checker.visit_name(name_node_y)
            self.checker.visit_name(name_node_print)
            self.checker.visit_name(name_node_j) 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:22,代码来源:test_possibly_undefined_checker.py

示例11: test_no_messages_with_import_from

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import parse [as 别名]
def test_no_messages_with_import_from(self):
        src = """
        from random import j
        
        y = 0
        if y > 10:
            j = 10
        else:
            y = 5
        print(j)
        """
        mod = astroid.parse(src)
        mod.accept(CFGVisitor())
        name_node_y, name_node_print, name_node_j = mod.nodes_of_class(astroid.Name)
        with self.assertNoMessages():
            self.checker.visit_module(mod)
            self.checker.visit_name(name_node_y)
            self.checker.visit_name(name_node_print)
            self.checker.visit_name(name_node_j) 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:21,代码来源:test_possibly_undefined_checker.py

示例12: test_no_messages_if_else

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import parse [as 别名]
def test_no_messages_if_else(self):
        src = """
        def test(x):
            if True:
                y = 10
            else:
                y = 20
            print(y)
        """
        mod = astroid.parse(src)
        mod.accept(CFGVisitor())
        func_node = mod.body[0]
        _, name_node_y = mod.nodes_of_class(astroid.Name)

        with self.assertNoMessages():
            self.checker.visit_functiondef(func_node)
            self.checker.visit_name(name_node_y) 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:19,代码来源:test_possibly_undefined_checker.py

示例13: test_no_messages_complex

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import parse [as 别名]
def test_no_messages_complex(self):
        src = """
        def test(x):
            if True:
                y = 10
            else:
                for j in range(10):
                    if j > 10:
                        y = 10
                        break
                else:
                    y = 10
            return y
        """
        mod = astroid.parse(src)
        mod.accept(CFGVisitor())
        func_node = mod.body[0]
        _, _, name_node_y = mod.nodes_of_class(astroid.Name)

        with self.assertNoMessages():
            self.checker.visit_functiondef(func_node)
            self.checker.visit_name(name_node_y) 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:24,代码来源:test_possibly_undefined_checker.py

示例14: test_no_messages_with_nonlocal

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import parse [as 别名]
def test_no_messages_with_nonlocal(self):
        src = """
        def test(x):
            x = 10
            nonlocal y
            if True:
                y = 10
            print(y)
        """
        mod = astroid.parse(src)
        mod.accept(CFGVisitor())
        func_node = mod.body[0]
        __, name_node_y = mod.nodes_of_class(astroid.Name)

        with self.assertNoMessages():
            self.checker.visit_functiondef(func_node)
            self.checker.visit_name(name_node_y) 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:19,代码来源:test_possibly_undefined_checker.py

示例15: test_no_messages_with_global

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import parse [as 别名]
def test_no_messages_with_global(self):
        src = """
        def test(x):
            x = 10
            if True:
                global y
            else:
                y = 10
            print(y)
        """
        mod = astroid.parse(src)
        mod.accept(CFGVisitor())
        func_node = mod.body[0]
        _, name_node_y = mod.nodes_of_class(astroid.Name)

        with self.assertNoMessages():
            self.checker.visit_functiondef(func_node)
            self.checker.visit_name(name_node_y) 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:20,代码来源:test_possibly_undefined_checker.py


注:本文中的astroid.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。