@@ -47,25 +47,25 @@ async def true() -> bool:
4747 return bool(int() + await one())
4848
4949async def branch_await() -> int:
50- if await true():
50+ if bool(int() + 1) == await true():
5151 return 3
5252 return 2
5353
5454async def branch_await_not() -> int:
55- if not await true():
55+ if bool(int() + 1) == ( not await true() ):
5656 return 3
5757 return 2
5858
5959def test_branch() -> None:
6060 assert asyncio.run(branch_await()) == 3
6161 assert asyncio.run(branch_await_not()) == 2
6262
63- async def assign_local () -> int:
64- x = await one()
63+ async def assign_multi () -> int:
64+ _, x = int(), await one()
6565 return x + 1
6666
67- def test_assign_local () -> None:
68- assert asyncio.run(assign_local ()) == 2
67+ def test_assign_multi () -> None:
68+ assert asyncio.run(assign_multi ()) == 2
6969
7070class C:
7171 def __init__(self, s: str) -> None:
@@ -78,81 +78,46 @@ async def make_c(s: str) -> C:
7878 await one()
7979 return C(s)
8080
81- async def get_attr(s: str) -> str:
82- return (await make_c(s)).s
83-
84- def test_get_attr() -> None:
85- assert asyncio.run(get_attr("foo")) == "foo"
86-
8781async def concat(s: str, t: str) -> str:
8882 await one()
8983 return s + t
9084
91- async def set_attr1(s: str) -> str:
92- c = await make_c("xyz")
93- c.s = await concat(s, "!")
94- return c.s
95-
96- async def set_attr2(s: str) -> None:
97- (await make_c("xyz")).s = s
85+ async def set_attr(s: str) -> None:
86+ (await make_c("xyz")).s = await concat(s, "!")
9887
9988def test_set_attr() -> None:
100- assert asyncio.run(set_attr1("foo")) == "foo!"
101- asyncio.run(set_attr2("foo")) # Just check that it compiles and runs
89+ asyncio.run(set_attr("foo")) # Just check that it compiles and runs
10290
103- def upper(s : str) -> str:
104- return s.upper()
91+ def concat2(x: str, y : str) -> str:
92+ return x + y
10593
10694async def call1(s: str) -> str:
107- return upper( await concat(s, "a"))
95+ return concat2(str(int()), await concat(s, "a"))
10896
10997async def call2(s: str) -> str:
110- return await concat(await concat(s, "a"), "b" )
98+ return await concat(str(int()), await concat(s, "b") )
11199
112100def test_call() -> None:
113- assert asyncio.run(call1("foo")) == "FOOA "
114- assert asyncio.run(call2("foo")) == "fooab "
101+ assert asyncio.run(call1("foo")) == "0fooa "
102+ assert asyncio.run(call2("foo")) == "0foob "
115103
116104async def method_call(s: str) -> str:
117- c = C("<")
118- return c.concat(await concat(s, ">"))
105+ return C("<").concat(await concat(s, ">"))
119106
120107def test_method_call() -> None:
121108 assert asyncio.run(method_call("foo")) == "<foo>"
122109
110+ class D:
111+ def __init__(self, a: str, b: str) -> None:
112+ self.a = a
113+ self.b = b
114+
123115async def construct(s: str) -> str:
124- c = C (await concat(s, "!"))
125- return c.s
116+ c = D (await concat(s, "!"), await concat(s, "? "))
117+ return c.a + c.b
126118
127119def test_construct() -> None:
128- assert asyncio.run(construct("foo")) == "foo!"
129-
130- async def repr_as_object(s: str) -> object:
131- return repr(s)
132-
133- async def do_cast(s: str) -> str:
134- return cast(str, await repr_as_object(s))
135-
136- def test_cast() -> None:
137- assert asyncio.run(do_cast("foo")) == "'foo'"
138-
139- async def box() -> list[int]:
140- return [await one(), await one()]
141-
142- def test_box() -> None:
143- assert asyncio.run(box()) == [1, 1]
144-
145- async def int_as_any(n: int) -> Any:
146- return n * 2
147-
148- async def inc(n: int) -> int:
149- return n + await one()
150-
151- async def unbox(n: int) -> int:
152- return await inc(await int_as_any(n))
153-
154- def test_unbox() -> None:
155- assert asyncio.run(unbox(4)) == 9
120+ assert asyncio.run(construct("foo")) == "foo!foo?"
156121
157122[file asyncio/__init__.pyi]
158123async def sleep(t: float) -> None: ...
0 commit comments