本文整理汇总了Python中nope.nodes.assign函数的典型用法代码示例。如果您正苦于以下问题:Python assign函数的具体用法?Python assign怎么用?Python assign使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assign函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: attributes_assigned_in_init_can_be_used_outside_of_class
def attributes_assigned_in_init_can_be_used_outside_of_class():
init_func = nodes.func(
name="__init__",
args=nodes.args([nodes.arg("self_init")]),
body=[
nodes.assign(
[nodes.attr(nodes.ref("self_init"), "message")],
nodes.str_literal("Hello"),
type=nodes.ref("str"),
)
],
type=nodes.signature(
args=[nodes.signature_arg(nodes.ref("Self"))],
returns=nodes.ref("none")
)
)
class_node = nodes.class_("User", [init_func])
node = [
class_node,
nodes.assign([nodes.ref("x")], nodes.attr(nodes.call(nodes.ref("User"), []), "message")),
]
context = _update_context(node, declared_names_in_node=NodeDict([
(class_node, ["Self", "__init__"]),
(init_func, ["self_init"]),
]))
assert_equal(types.str_type, context.lookup_name("x"))
开发者ID:mwilliamson,项目名称:nope,代码行数:29,代码来源:statements_tests.py
示例2: error_is_raised_if_all_is_redeclared
def error_is_raised_if_all_is_redeclared():
try:
all_node = nodes.assign(["__all__"], nodes.list_literal([]))
second_all_node = nodes.assign(["__all__"], nodes.list_literal([]))
_exported_names(nodes.module([all_node, second_all_node]))
assert False, "Expected error"
except errors.AllAssignmentError as error:
assert_equal(second_all_node, error.node)
assert_equal("__all__ cannot be redeclared", str(error))
开发者ID:mwilliamson,项目名称:nope,代码行数:9,代码来源:module_tests.py
示例3: module_exports_default_to_values_without_leading_underscore_if_all_is_not_specified
def module_exports_default_to_values_without_leading_underscore_if_all_is_not_specified():
module_node = nodes.module([
nodes.assign(["x"], nodes.str_literal("one")),
nodes.assign(["_y"], nodes.str_literal("two")),
nodes.assign(["z"], nodes.int_literal(3)),
])
module, type_lookup = _check(LocalModule(None, module_node))
assert_equal(types.str_type, module.attrs.type_of("x"))
assert_equal(None, module.attrs.get("_y"))
assert_equal(types.int_type, module.attrs.type_of("z"))
开发者ID:mwilliamson,项目名称:nope,代码行数:11,代码来源:inference_tests.py
示例4: module_exports_are_specified_using_all
def module_exports_are_specified_using_all():
module_node = nodes.module([
nodes.assign(["__all__"], nodes.list_literal([nodes.str_literal("x"), nodes.str_literal("z")])),
nodes.assign(["x"], nodes.str_literal("one")),
nodes.assign(["y"], nodes.str_literal("two")),
nodes.assign(["z"], nodes.int_literal(3)),
])
module, type_lookup = _check(LocalModule(None, module_node))
assert_equal(types.str_type, module.attrs.type_of("x"))
assert_equal(None, module.attrs.get("y"))
assert_equal(types.int_type, module.attrs.type_of("z"))
开发者ID:mwilliamson,项目名称:nope,代码行数:12,代码来源:inference_tests.py
示例5: attributes_assigned_in_init_can_be_used_in_methods_when_init_method_is_defined_after_other_method
def attributes_assigned_in_init_can_be_used_in_methods_when_init_method_is_defined_after_other_method():
init_func = nodes.func(
name="__init__",
args=nodes.args([nodes.arg("self_init")]),
body=[
nodes.assign(
[nodes.attr(nodes.ref("self_init"), "message")],
nodes.str_literal("Hello"),
type=nodes.ref("str"),
)
],
type=nodes.signature(
args=[nodes.signature_arg(nodes.ref("Self"))],
returns=nodes.ref("none")
),
)
node = nodes.class_("User", [
nodes.func(
name="g",
args=nodes.args([nodes.arg("self_g")]),
body=[nodes.ret(nodes.attr(nodes.ref("self_g"), "message"))],
type=nodes.signature(
args=[nodes.signature_arg(nodes.ref("Self"))],
returns=nodes.ref("str")
),
),
init_func,
])
_infer_class_type(node, ["__init__", "g"], [(init_func, ["self_init"])])
开发者ID:mwilliamson,项目名称:nope,代码行数:29,代码来源:class_definition_tests.py
示例6: init_method_cannot_call_other_methods
def init_method_cannot_call_other_methods():
node = nodes.class_("User", [
nodes.func(
name="__init__",
args=nodes.args([nodes.arg("self_init")]),
body=[
nodes.assign([nodes.ref("x")], nodes.call(nodes.attr(nodes.ref("self_init"), "g"), []))
],
type=nodes.signature(
args=[nodes.signature_arg(nodes.ref("Self"))],
returns=nodes.ref("none")
),
),
nodes.func(
name="g",
args=nodes.args([nodes.arg("self_g")]),
body=[],
type=nodes.signature(
args=[nodes.signature_arg(nodes.ref("Self"))],
returns=nodes.ref("none")
),
),
])
try:
_infer_class_type(node, ["__init__", "g"])
assert False, "Expected error"
except errors.InitMethodCannotGetSelfAttributes as error:
assert_equal("__init__ methods cannot get attributes of self", str(error))
开发者ID:mwilliamson,项目名称:nope,代码行数:28,代码来源:class_definition_tests.py
示例7: can_assign_value_of_subtype_to_variable
def can_assign_value_of_subtype_to_variable():
target_node = nodes.ref("x")
node = nodes.assign([target_node], nodes.int_literal(1))
type_bindings = {"x": types.object_type}
context = update_context(node, type_bindings=type_bindings)
assert_equal(types.object_type, context.lookup_name("x"))
开发者ID:mwilliamson,项目名称:nope,代码行数:7,代码来源:assignment_tests.py
示例8: names_in_class_are_not_declared_in_outer_scope
def names_in_class_are_not_declared_in_outer_scope():
node = nodes.class_("User", [
nodes.assign([nodes.ref("x")], nodes.none())
])
declarations = find_declarations(node)
assert not declarations.is_declared("x")
开发者ID:mwilliamson,项目名称:nope,代码行数:7,代码来源:name_declaration_tests.py
示例9: names_in_function_are_not_declared_in_outer_scope
def names_in_function_are_not_declared_in_outer_scope():
node = nodes.func("f", nodes.arguments([]), [
nodes.assign([nodes.ref("x")], nodes.none())
], type=None)
declarations = find_declarations(node)
assert not declarations.is_declared("x")
开发者ID:mwilliamson,项目名称:nope,代码行数:7,代码来源:name_declaration_tests.py
示例10: declarations_in_function_include_declarations_in_body
def declarations_in_function_include_declarations_in_body():
node = nodes.func("f", nodes.arguments([]), [
nodes.assign([nodes.ref("x")], nodes.none())
], type=None)
declarations = _declarations_in(node)
assert isinstance(declarations.declaration("x"), name_declaration.VariableDeclarationNode)
assert not declarations.is_declared("f")
开发者ID:mwilliamson,项目名称:nope,代码行数:8,代码来源:name_declaration_tests.py
示例11: test_transform_setitem_subscript
def test_transform_setitem_subscript(self):
_assert_transform(
nodes.assign([nodes.subscript(nodes.ref("x"), nodes.ref("y"))], nodes.ref("z")),
"""
var __nope_u_tmp0 = z
x.__setitem__(y, __nope_u_tmp0)
"""
)
开发者ID:mwilliamson,项目名称:nope,代码行数:8,代码来源:desugar_tests.py
示例12: check_generates_type_lookup_for_all_expressions
def check_generates_type_lookup_for_all_expressions():
int_ref_node = nodes.ref("a")
int_node = nodes.int_literal(3)
str_node = nodes.str_literal("Hello")
module_node = nodes.module([
nodes.assign(["a"], int_node),
nodes.func("f", nodes.args([]), [
nodes.assign("b", int_ref_node),
nodes.assign("c", str_node),
], type=None),
])
module, type_lookup = _check(LocalModule(None, module_node))
assert_equal(types.int_type, type_lookup.type_of(int_node))
assert_equal(types.int_type, type_lookup.type_of(int_ref_node))
assert_equal(types.str_type, type_lookup.type_of(str_node))
开发者ID:mwilliamson,项目名称:nope,代码行数:17,代码来源:inference_tests.py
示例13: only_values_that_are_definitely_bound_are_exported
def only_values_that_are_definitely_bound_are_exported():
module_node = nodes.module([
nodes.if_(
nodes.bool_literal(True),
[
nodes.assign(["x"], nodes.str_literal("one")),
nodes.assign(["y"], nodes.str_literal("two")),
],
[
nodes.assign(["y"], nodes.str_literal("three")),
]
)
])
module, type_lookup = _check(LocalModule(None, module_node))
assert_equal(None, module.attrs.get("x"))
assert_equal(types.str_type, module.attrs.type_of("y"))
开发者ID:mwilliamson,项目名称:nope,代码行数:17,代码来源:inference_tests.py
示例14: attributes_with_function_type_defined_in_class_definition_body_are_not_present_on_meta_type
def attributes_with_function_type_defined_in_class_definition_body_are_not_present_on_meta_type():
node = nodes.class_("User", [
nodes.assign([nodes.ref("is_person")], nodes.ref("true_func")),
])
meta_type = _infer_meta_type(node, ["is_person"], type_bindings={
"true_func": types.func([types.object_type], types.none_type)
})
assert "is_person" not in meta_type.attrs
开发者ID:mwilliamson,项目名称:nope,代码行数:8,代码来源:class_definition_tests.py
示例15: declarations_in_class_include_declarations_in_body
def declarations_in_class_include_declarations_in_body():
node = nodes.class_("User", [
nodes.assign([nodes.ref("x")], nodes.none())
])
declarations = _declarations_in(node)
assert isinstance(declarations.declaration("x"), name_declaration.VariableDeclarationNode)
assert not declarations.is_declared("User")
开发者ID:mwilliamson,项目名称:nope,代码行数:8,代码来源:name_declaration_tests.py
示例16: error_is_raised_if_all_is_not_a_list
def error_is_raised_if_all_is_not_a_list():
try:
all_node = nodes.assign(["__all__"], nodes.none())
_exported_names(nodes.module([all_node]))
assert False, "Expected error"
except errors.AllAssignmentError as error:
assert_equal(all_node, error.node)
assert_equal("__all__ must be a list of string literals", str(error))
开发者ID:mwilliamson,项目名称:nope,代码行数:8,代码来源:module_tests.py
示例17: assignment_to_tuple_declares_variables_in_tuple
def assignment_to_tuple_declares_variables_in_tuple():
first_definition_node = nodes.ref("x")
second_definition_node = nodes.ref("y")
node = nodes.assign([nodes.tuple_literal([first_definition_node, second_definition_node])], nodes.none())
declarations = find_declarations(node)
assert_equal("x", declarations.declaration("x").name)
assert_equal("y", declarations.declaration("y").name)
assert isinstance(declarations.declaration("x"), name_declaration.VariableDeclarationNode)
assert isinstance(declarations.declaration("y"), name_declaration.VariableDeclarationNode)
开发者ID:mwilliamson,项目名称:nope,代码行数:9,代码来源:name_declaration_tests.py
示例18: values_can_have_same_name_as_child_module_if_they_are_not_in_module_scope
def values_can_have_same_name_as_child_module_if_they_are_not_in_module_scope():
value_node = nodes.assign([nodes.ref("x")], nodes.int_literal(1))
node = nodes.module([
nodes.func("f", nodes.args([]), [value_node], type=None)
], is_executable=False)
_check_module(LocalModule("root/__init__.py", node), {
(".", "x"): module({}),
})
开发者ID:mwilliamson,项目名称:nope,代码行数:9,代码来源:inference_tests.py
示例19: _create_module
def _create_module(path, is_executable=False, declares=[]):
declarations = [
nodes.assign([nodes.ref(name)], nodes.none())
for name in declares
]
return LocalModule(
path=path,
node=nodes.module(declarations, is_executable=is_executable)
)
开发者ID:mwilliamson,项目名称:nope,代码行数:9,代码来源:module_resolution_tests.py
示例20: test_transform_compound_assignments
def test_transform_compound_assignments(self):
_assert_transform(
nodes.assign(["x", "y"], nodes.ref("z")),
cc.statements([
cc.declare("__nope_u_tmp0", cc.ref("z")),
cc.assign(cc.ref("x"), cc.ref("__nope_u_tmp0")),
cc.assign(cc.ref("y"), cc.ref("__nope_u_tmp0")),
]),
)
开发者ID:mwilliamson,项目名称:nope,代码行数:9,代码来源:desugar_tests.py
注:本文中的nope.nodes.assign函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论