本文整理汇总了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
''')
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)