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


Python nodes.ref函数代码示例

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


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

示例1: can_parse_signature_comment_with_one_formal_type_parameter

def can_parse_signature_comment_with_one_formal_type_parameter():
    expected_signature = nodes.signature(
        type_params=[nodes.formal_type_parameter("T")],
        args=[nodes.signature_arg(nodes.ref("T"))],
        returns=nodes.ref("T")
    )
    assert_equal(expected_signature, parse_explicit_type("T => T -> T"))
开发者ID:mwilliamson,项目名称:nope,代码行数:7,代码来源:typing_tests.py

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

示例3: test_parse_call_with_keyword_arguments

def test_parse_call_with_keyword_arguments():
    expected = nodes.call(
        nodes.ref("f"),
        [],
        {"person": nodes.ref("bob"), "hat": nodes.ref("fedora")},
    )
    _assert_expression_parse(expected, "f(person=bob, hat=fedora)")
开发者ID:mwilliamson,项目名称:nope,代码行数:7,代码来源:parser_tests.py

示例4: test_parse_if_else_statement

def test_parse_if_else_statement():
    expected = nodes.if_(
        nodes.ref("b"),
        [nodes.ret(nodes.ref("x"))],
        [nodes.ret(nodes.ref("y"))],
    )
    _assert_statement_parse(expected, "if b:\n  return x\nelse:\n  return y")
开发者ID:mwilliamson,项目名称:nope,代码行数:7,代码来源:parser_tests.py

示例5: test_parse_with_statement_single_context_manager_with_target

def test_parse_with_statement_single_context_manager_with_target():
    expected_node = nodes.with_(
        nodes.ref("x"),
        nodes.ref("x2"),
        [nodes.ret(nodes.ref("y"))],
    )
    _assert_statement_parse(expected_node, "with x as x2:\n  return y")
开发者ID:mwilliamson,项目名称:nope,代码行数:7,代码来源:parser_tests.py

示例6: test_parse_try_finally

def test_parse_try_finally():
    expected = nodes.try_(
        [nodes.expression_statement(nodes.ref("x"))],
        finally_body=[nodes.expression_statement(nodes.ref("y"))],
    )
    
    _assert_statement_parse(expected, "try:\n  x\nfinally:\n  y")
开发者ID:mwilliamson,项目名称:nope,代码行数:7,代码来源:parser_tests.py

示例7: type_of_add_method_argument_allows_super_type

def type_of_add_method_argument_allows_super_type():
    cls = types.class_type("Addable", {})
    cls.attrs.add("__add__", types.func([types.object_type], cls))
    
    type_bindings = {"x": cls, "y": cls}
    addition = nodes.add(nodes.ref("x"), nodes.ref("y"))
    assert_equal(cls, infer(addition, type_bindings=type_bindings))
开发者ID:mwilliamson,项目名称:nope,代码行数:7,代码来源:operators_tests.py

示例8: return_type_of_add_can_differ_from_original_type

def return_type_of_add_can_differ_from_original_type():
    cls = types.class_type("Addable", {})
    cls.attrs.add("__add__", types.func([types.object_type], types.object_type))
    
    type_bindings = {"x": cls, "y": cls}
    addition = nodes.add(nodes.ref("x"), nodes.ref("y"))
    assert_equal(types.object_type, infer(addition, type_bindings=type_bindings))
开发者ID:mwilliamson,项目名称:nope,代码行数:7,代码来源:operators_tests.py

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

示例10: list_comprehension_target_is_definitely_bound

def list_comprehension_target_is_definitely_bound():
    node = nodes.list_comprehension(
        nodes.ref("x"),
        nodes.ref("x"),
        nodes.list_literal([]),
    )
    
    _updated_bindings(node)
开发者ID:mwilliamson,项目名称:nope,代码行数:8,代码来源:name_binding_tests.py

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

示例12: type_name_is_definitely_bound_after_type_definition

def type_name_is_definitely_bound_after_type_definition():
    int_ref = nodes.ref("int")
    str_ref = nodes.ref("str")
    
    node = nodes.type_definition("Identifier", nodes.type_union([int_ref, str_ref]))
    
    bindings = _updated_bindings(node, is_definitely_bound=["int", "str"])
    assert_equal(True, bindings.is_definitely_bound(node))
开发者ID:mwilliamson,项目名称:nope,代码行数:8,代码来源:name_binding_tests.py

示例13: operands_of_sub_operation_must_support_sub

def operands_of_sub_operation_must_support_sub():
    type_bindings = {"x": types.none_type, "y": types.none_type}
    subtraction = nodes.sub(nodes.ref("x"), nodes.ref("y"))
    try:
        infer(subtraction, type_bindings=type_bindings)
        assert False, "Expected error"
    except errors.NoSuchAttributeError as error:
        assert_equal(nodes.attr(subtraction.left, "__sub__"), error.node)
开发者ID:mwilliamson,项目名称:nope,代码行数:8,代码来源:operators_tests.py

示例14: for_statement_target_can_be_supertype_of_iterable_element_type

def for_statement_target_can_be_supertype_of_iterable_element_type():
    ref_node = nodes.ref("xs")
    node = nodes.for_(nodes.subscript(nodes.ref("ys"), nodes.int_literal(0)), ref_node, [])
    
    update_context(node, type_bindings={
        "xs": types.list_type(types.int_type),
        "ys": types.list_type(types.object_type),
    })
开发者ID:mwilliamson,项目名称:nope,代码行数:8,代码来源:for_loop_tests.py

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


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