• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python nodes.func函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中nope.nodes.func函数的典型用法代码示例。如果您正苦于以下问题:Python func函数的具体用法?Python func怎么用?Python func使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: function_definitions_in_statement_lists_can_be_defined_out_of_order

def function_definitions_in_statement_lists_can_be_defined_out_of_order():
    f = nodes.func("f", type=None, args=nodes.Arguments([]), body=[
        nodes.ret(nodes.call(nodes.ref("g"), []))
    ])
    g = nodes.func("g", type=None, args=nodes.Arguments([]), body=[])
    
    _updated_bindings(nodes.module([f, g]))
开发者ID:mwilliamson,项目名称:nope,代码行数:7,代码来源:name_binding_tests.py


示例2: 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


示例3: 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


示例4: method_can_call_method_on_same_instance_defined_later_in_body

def method_can_call_method_on_same_instance_defined_later_in_body():
    node = nodes.class_("User", [
        nodes.func(
            name="f",
            args=nodes.args([nodes.arg("self_f")]),
            body=[
                nodes.ret(nodes.call(nodes.attr(nodes.ref("self_f"), "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=[
                nodes.ret(nodes.call(nodes.attr(nodes.ref("self_g"), "f"), []))
            ],
            type=nodes.signature(
                args=[nodes.signature_arg(nodes.ref("Self"))],
                returns=nodes.ref("none")
            ),
        )
    ])
    _infer_class_type(node, ["f", "g"])
开发者ID:mwilliamson,项目名称:nope,代码行数:26,代码来源:class_definition_tests.py


示例5: function_definitions_in_statement_lists_can_be_mutually_recursive

def function_definitions_in_statement_lists_can_be_mutually_recursive():
    f = nodes.func("f", type=None, args=nodes.Arguments([]), body=[
        nodes.ret(nodes.call(nodes.ref("g"), []))
    ])
    g = nodes.func("g", type=None, args=nodes.Arguments([]), body=[
        nodes.ret(nodes.call(nodes.ref("f"), []))
    ])
    _update_context([f, g])
开发者ID:mwilliamson,项目名称:nope,代码行数:8,代码来源:statements_tests.py


示例6: function_definitions_can_be_mutually_recursive

def function_definitions_can_be_mutually_recursive():
    f = nodes.func("f", type=None, args=nodes.Arguments([]), body=[
        nodes.ret(nodes.call(nodes.ref("g"), []))
    ])
    g = nodes.func("g", type=None, args=nodes.Arguments([]), body=[
        nodes.ret(nodes.call(nodes.ref("f"), []))
    ])
    
    _updated_bindings(nodes.module([f, g]))
开发者ID:mwilliamson,项目名称:nope,代码行数:9,代码来源:name_binding_tests.py


示例7: method_can_reference_later_function_if_class_is_not_used_in_the_interim

def method_can_reference_later_function_if_class_is_not_used_in_the_interim():
    g_ref = nodes.ref("g")
    f = nodes.func("f", type=None, args=nodes.Arguments([]), body=[
        nodes.ret(nodes.call(g_ref, []))
    ])
    g = nodes.func("g", type=None, args=nodes.Arguments([]), body=[])
    
    _updated_bindings(nodes.module([
        nodes.class_("a", [f]),
        g,
    ]))
开发者ID:mwilliamson,项目名称:nope,代码行数:11,代码来源:name_binding_tests.py


示例8: 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


示例9: exception_handler_targets_cannot_be_accessed_from_nested_function

def exception_handler_targets_cannot_be_accessed_from_nested_function():
    target_node = nodes.ref("error")
    ref_node = nodes.ref("error")
    body = [nodes.ret(ref_node)]
    func_node = nodes.func("f", nodes.arguments([]), body, type=None)
    try_node = nodes.try_(
        [],
        handlers=[
            nodes.except_(nodes.none(), target_node, [func_node])
        ],
    )
    
    declaration = name_declaration.ExceptionHandlerTargetNode("error")
    references = References([
        (target_node, declaration),
        (ref_node, declaration),
        (func_node, name_declaration.VariableDeclarationNode("f")),
    ])
    
    try:
        _updated_bindings(try_node, references=references)
        assert False, "Expected error"
    except errors.UnboundLocalError as error:
        assert_equal(ref_node, error.node)
        assert_is("error", error.name)
开发者ID:mwilliamson,项目名称:nope,代码行数:25,代码来源:name_binding_tests.py


示例10: class_cannot_be_referenced_if_method_dependencies_are_not_bound

def class_cannot_be_referenced_if_method_dependencies_are_not_bound():
    g_ref = nodes.ref("g")
    f = nodes.func("f", type=None, args=nodes.Arguments([]), body=[
        nodes.ret(nodes.call(g_ref, []))
    ])
    g = nodes.func("g", type=None, args=nodes.Arguments([]), body=[])
    
    try:
        _updated_bindings(nodes.module([
            nodes.class_("a", [f]),
            nodes.expression_statement(nodes.ref("a")),
            g,
        ]))
        assert False, "Expected error"
    except errors.UnboundLocalError as error:
        assert_equal(g_ref, error.node)
开发者ID:mwilliamson,项目名称:nope,代码行数:16,代码来源:name_binding_tests.py


示例11: can_infer_type_of_function_with_explicit_signature_of_aliased_function_type

def can_infer_type_of_function_with_explicit_signature_of_aliased_function_type():
    args = nodes.arguments([])
    node = nodes.func("f", args=args, body=[], type=nodes.ref("Action"))
    type_bindings = {
        "Action": types.meta_type(types.func([], types.none_type))
    }
    assert_equal(types.func([], types.none_type), _infer_func_type(node, type_bindings))
开发者ID:mwilliamson,项目名称:nope,代码行数:7,代码来源:function_definition_tests.py


示例12: 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


示例13: function_cannot_be_referenced_before_definition_of_dependencies

def function_cannot_be_referenced_before_definition_of_dependencies():
    g_ref = nodes.ref("g")
    f = nodes.func("f", type=None, args=nodes.Arguments([]), body=[
        nodes.ret(nodes.call(g_ref, []))
    ])
    g = nodes.func("g", type=None, args=nodes.Arguments([]), body=[])
    
    try:
        _updated_bindings(nodes.module([
            f,
            nodes.expression_statement(nodes.ref("f")),
            g,
        ]))
        assert False, "Expected error"
    except errors.UnboundLocalError as error:
        assert_equal(g_ref, error.node)
开发者ID:mwilliamson,项目名称:nope,代码行数:16,代码来源:name_binding_tests.py


示例14: 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


示例15: break_is_not_valid_in_function_in_while_loop_body

def break_is_not_valid_in_function_in_while_loop_body():
    break_node = nodes.break_()
    func_node = nodes.func("f", nodes.args([]), [break_node], type=None)
    node = nodes.while_(nodes.bool_literal(True), [func_node], [])
    error = assert_raises(errors.TypeCheckError,
        lambda: check_loop_control(node, False))
    assert_equal(break_node, error.node)
    assert_equal("'break' outside loop", str(error))
开发者ID:mwilliamson,项目名称:nope,代码行数:8,代码来源:loop_control_tests.py


示例16: function_definitions_in_statement_lists_are_type_checked_even_if_not_invoked

def function_definitions_in_statement_lists_are_type_checked_even_if_not_invoked():
    node = nodes.func("f", type=None, args=nodes.Arguments([]), body=[nodes.ret(nodes.int_literal(42))])
    try:
        _update_context([node])
        assert False, "Expected error"
    except errors.UnexpectedValueTypeError as error:
        assert_equal(types.int_type, error.actual)
        assert_equal(types.none_type, error.expected)
开发者ID:mwilliamson,项目名称:nope,代码行数:8,代码来源:statements_tests.py


示例17: type_parameters_of_function_are_definitely_bound

def type_parameters_of_function_are_definitely_bound():
    param = nodes.formal_type_parameter("T")
    arg_ref = nodes.ref("T")
    returns_ref = nodes.ref("T")
    explicit_type = nodes.signature(type_params=[param], args=[nodes.signature_arg(arg_ref)], returns=returns_ref)
    func_node = nodes.func("f", nodes.arguments([]), [], type=explicit_type)
    
    _updated_bindings(func_node)
开发者ID:mwilliamson,项目名称:nope,代码行数:8,代码来源:name_binding_tests.py


示例18: test_function_definitions_in_body_are_stored_as_methods

 def test_function_definitions_in_body_are_stored_as_methods(self):
     _assert_transform(
         nodes.class_("Blah", [nodes.func("f", nodes.args([]), [], type=None)]),
         cc.class_(
             "Blah",
             methods=[cc.func("f", [], [cc.ret(cc.none)])],
             body=[cc.declare("f")],
         ),
     )
开发者ID:mwilliamson,项目名称:nope,代码行数:9,代码来源:desugar_tests.py


示例19: _create_class_with_init

def _create_class_with_init(signature, args, body):
    return nodes.class_("User", [
        nodes.func(
            name="__init__",
            args=args,
            body=body,
            type=signature
        )
    ])
开发者ID:mwilliamson,项目名称:nope,代码行数:9,代码来源:class_definition_tests.py


示例20: function_adds_arguments_to_context

def function_adds_arguments_to_context():
    signature = nodes.signature(
        args=[nodes.signature_arg(nodes.ref("int"))],
        returns=nodes.ref("int")
    )
    args = nodes.arguments([nodes.argument("x")])
    body = [nodes.ret(nodes.ref("x"))]
    node = nodes.func("f", args, body, type=signature)
    assert_equal(types.func([types.int_type], types.int_type), _infer_func_type(node))
开发者ID:mwilliamson,项目名称:nope,代码行数:9,代码来源:function_definition_tests.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python nodes.ref函数代码示例发布时间:2022-05-27
下一篇:
Python nodes.assign函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap