def test_ignores(): expected = [ (2, ''), (5, ''), (8, '[excuse]'), (9, '=excuse'), (10, ' [excuse]'), (11, ' whatever'), ] for version in range(MIN_VER, NEXT_VER): tree = _ast3._parse(ignores, "<ignores>", "exec", version) assert [(ti.lineno, ti.tag) for ti in tree.type_ignores] == expected with pytest.raises(SyntaxError): _ast3._parse("pass # type: ignoreé\n", "<ignores>", "exec", version) tree = _ast27.parse(ignores, "<ignores>", "exec") assert [(ti.lineno, ti.tag) for ti in tree.type_ignores] == expected with pytest.raises(SyntaxError): _ast27.parse("pass # type: ignoreé\n", "<ignores>", "exec")
def test_convert_strs(): ast = _ast27.parse(basic_py2, "<basic_py2>", "exec") tree = typed_ast.conversions.py2to3(ast) assert tree.body[0].value.kind == "" assert tree.body[1].value.kind == "u" assert tree.body[2].value.kind == "b"
def parse(source, filename="<unknown>", mode="exec"): """ Parse the source into an AST node with type comments. Equivalent to compile(source, filename, mode, PyCF_ONLY_AST). """ return _ast27.parse(source, filename, mode)