當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。