示例#1
0
def when_target_has_explicit_type_that_type_is_used_as_type_hint():
    node = nodes.assign(
        [nodes.ref("x")],
        nodes.list_literal([nodes.str_literal("Hello")]),
        type=nodes.type_apply(nodes.ref("list"), [nodes.ref("object")])
    )
    context = update_context(node, type_bindings={
        "list": types.meta_type(types.list_type),
        "object": types.meta_type(types.object_type),
    })
    assert_equal(types.list_type(types.object_type), context.lookup_name("x"))
示例#2
0
def test_assignment_can_have_explicit_type():
    expected = nodes.assign(
        ["x"], nodes.list_literal([]),
        type=nodes.type_apply(nodes.ref("list"), [nodes.ref("str")])
    )
    _assert_statement_parse(expected, "#:: list[str]\nx = []")
示例#3
0
def can_parse_signature_comment_with_type_application_with_one_generic_parameter():
    expected_signature = nodes.signature(
        returns=nodes.type_apply(nodes.ref("list"), [nodes.ref("str")])
    )
    assert_equal(expected_signature, parse_explicit_type("-> list[str]"))
示例#4
0
def can_parse_signature_comment_with_type_application_with_many_generic_parameters():
    expected_signature = nodes.signature(
        returns=nodes.type_apply(nodes.ref("dict"), [nodes.ref("str"), nodes.ref("int")]),
    )
    assert_equal(expected_signature, parse_explicit_type("-> dict[str, int]"))
示例#5
0
def can_parse_explicit_type_with_type_application_with_one_generic_parameter():
    assert_equal(
        nodes.type_apply(nodes.ref("list"), [nodes.ref("str")]),
        parse_explicit_type("list[str]")
    )