MCPcopy Create free account
hub / github.com/astral-sh/ruff / unparse

Function unparse

crates/ruff_python_codegen/src/generator.rs:1712–1932  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1710
1711 #[test]
1712 fn unparse() {
1713 assert_round_trip!("{i for i in b async for i in a if await i for b in i}");
1714 assert_round_trip!("f(**x)");
1715 assert_round_trip!("{**x}");
1716 assert_round_trip!("f(**([] or 5))");
1717 assert_round_trip!(r#"my_function(*[1], *[2], **{"three": 3}, **{"four": "four"})"#);
1718 assert_round_trip!("{**([] or 5)}");
1719 assert_round_trip!("del l[0]");
1720 assert_round_trip!("del obj.x");
1721 assert_round_trip!("a @ b");
1722 assert_round_trip!("a @= b");
1723 assert_round_trip!("x.foo");
1724 assert_round_trip!("return await (await bar())");
1725 assert_round_trip!("(5).foo");
1726 assert_round_trip!(r#"our_dict = {"a": 1, **{"b": 2, "c": 3}}"#);
1727 assert_round_trip!(r"j = [1, 2, 3]");
1728 assert_round_trip!(
1729 r#"def test(a1, a2, b1=j, b2="123", b3={}, b4=[]):
1730 pass"#
1731 );
1732 assert_round_trip!("a @ b");
1733 assert_round_trip!("a @= b");
1734 assert_round_trip!("[1, 2, 3]");
1735 assert_round_trip!("foo(1)");
1736 assert_round_trip!("foo(1, 2)");
1737 assert_round_trip!("foo(x for x in y)");
1738 assert_round_trip!("foo([x for x in y])");
1739 assert_round_trip!("foo([(x := 2) for x in y])");
1740 assert_round_trip!("x = yield 1");
1741 assert_round_trip!("return (yield 1)");
1742 assert_round_trip!("lambda: (1, 2, 3)");
1743 assert_round_trip!("return 3 and 4");
1744 assert_round_trip!("return 3 or 4");
1745 assert_round_trip!("yield from some()");
1746 assert_round_trip!(r#"assert (1, 2, 3), "msg""#);
1747 assert_round_trip!("import ast");
1748 assert_round_trip!("import operator as op");
1749 assert_round_trip!("from math import floor");
1750 assert_round_trip!("from .. import foobar");
1751 assert_round_trip!("from ..aaa import foo, bar as bar2");
1752 assert_round_trip!(r#"return f"functools.{qualname}({', '.join(args)})""#);
1753 assert_round_trip!(r#"my_function(*[1], *[2], **{"three": 3}, **{"four": "four"})"#);
1754 assert_round_trip!(r#"our_dict = {"a": 1, **{"b": 2, "c": 3}}"#);
1755 assert_round_trip!("f(**x)");
1756 assert_round_trip!("{**x}");
1757 assert_round_trip!("f(**([] or 5))");
1758 assert_round_trip!("{**([] or 5)}");
1759 assert_round_trip!(r#"return f"functools.{qualname}({', '.join(args)})""#);
1760 assert_round_trip!(
1761 r#"class TreeFactory(*[FactoryMixin, TreeBase], **{"metaclass": Foo}):
1762 pass"#
1763 );
1764 assert_round_trip!(
1765 r"class Foo(Bar, object):
1766 pass"
1767 );
1768 assert_round_trip!(
1769 r"class Foo[T]:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected