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

Python nodes.ref函数代码示例

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

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



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


示例16: test_parse_chained_boolean_operators

def test_parse_chained_boolean_operators():
    _assert_expression_parse(
        nodes.bool_and(
            nodes.bool_and(nodes.ref("a"), nodes.ref("b")),
            nodes.ref("c"),
        ),
        "a and b and c"
    )
开发者ID:mwilliamson,项目名称:nope,代码行数:8,代码来源:parser_tests.py


示例17: test_parse_for_loop_with_else_body

def test_parse_for_loop_with_else_body():
    expected = nodes.for_(
        nodes.ref("x"), nodes.ref("xs"),
        [],
        [nodes.ret(nodes.ref("x"))],
    )
    
    _assert_statement_parse(expected, "for x in xs:\n  pass\nelse:\n  return x")
开发者ID:mwilliamson,项目名称:nope,代码行数:8,代码来源:parser_tests.py


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


示例19: test_parse_single_comparison

def test_parse_single_comparison():
    x = nodes.ref("x")
    y = nodes.ref("y")
    _assert_expression_parse(nodes.eq(x, y), "x == y")
    _assert_expression_parse(nodes.ne(x, y), "x != y")
    _assert_expression_parse(nodes.lt(x, y), "x < y")
    _assert_expression_parse(nodes.le(x, y), "x <= y")
    _assert_expression_parse(nodes.gt(x, y), "x > y")
    _assert_expression_parse(nodes.ge(x, y), "x >= y")
开发者ID:mwilliamson,项目名称:nope,代码行数:9,代码来源:parser_tests.py


示例20: test_transform_boolean_or

 def test_transform_boolean_or(self):
     _assert_transform(
         nodes.bool_or(nodes.ref("x"), nodes.ref("y")),
         cc.ternary_conditional(
             cc.call(cc.builtin("bool"), [cc.ref("x")]),
             cc.ref("x"),
             cc.ref("y")
         ),
     )
开发者ID:mwilliamson,项目名称:nope,代码行数:9,代码来源:desugar_tests.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python utils.getv函数代码示例发布时间:2022-05-27
下一篇:
Python nodes.func函数代码示例发布时间: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