From 60524c5ce0cdb4bc3ab5d333789676c06095a74c Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Sat, 21 May 2022 15:09:01 -0700 Subject: [PATCH 1/6] Use async def in pythoneval tests --- test-data/unit/pythoneval-asyncio.test | 90 +++++++++----------------- 1 file changed, 30 insertions(+), 60 deletions(-) diff --git a/test-data/unit/pythoneval-asyncio.test b/test-data/unit/pythoneval-asyncio.test index b3400fe6010e..b3c587b51f57 100644 --- a/test-data/unit/pythoneval-asyncio.test +++ b/test-data/unit/pythoneval-asyncio.test @@ -17,8 +17,7 @@ from typing import Any, Generator import asyncio from asyncio import Future -@asyncio.coroutine -def greet_every_two_seconds() -> 'Generator[Any, None, None]': +async def greet_every_two_seconds() -> 'Generator[Any, None, None]': n = 0 while n < 5: print('Prev', n) @@ -48,14 +47,12 @@ from typing import Generator, Any import asyncio from asyncio import Future -@asyncio.coroutine -def compute(x: int, y: int) -> 'Generator[Any, None, int]': +async def compute(x: int, y: int) -> 'Generator[Any, None, int]': print("Compute %s + %s ..." % (x, y)) yield from asyncio.sleep(0.1) return x + y # Here the int is wrapped in Future[int] -@asyncio.coroutine -def print_sum(x: int, y: int) -> 'Generator[Any, None, None]': +async def print_sum(x: int, y: int) -> 'Generator[Any, None, None]': result = yield from compute(x, y) # The type of result will be int (is extracted from Future[int] print("%s + %s = %s" % (x, y, result)) @@ -71,8 +68,7 @@ from typing import Generator, Any import asyncio from asyncio import Future -@asyncio.coroutine -def slow_operation(future: 'Future[str]') -> 'Generator[Any, None, None]': +async def slow_operation(future: 'Future[str]') -> 'Generator[Any, None, None]': yield from asyncio.sleep(0.1) future.set_result('Future is done!') @@ -91,8 +87,7 @@ from typing import Generator, Any import asyncio from asyncio import Future, AbstractEventLoop -@asyncio.coroutine -def slow_operation(future: 'Future[str]') -> 'Generator[Any, None, None]': +async def slow_operation(future: 'Future[str]') -> 'Generator[Any, None, None]': yield from asyncio.sleep(1) future.set_result('Callback works!') @@ -116,8 +111,7 @@ import typing from typing import Generator, Any import asyncio from asyncio import Task, Future -@asyncio.coroutine -def factorial(name, number) -> 'Generator[Any, None, None]': +async def factorial(name, number) -> 'Generator[Any, None, None]': f = 1 for i in range(2, number+1): print("Task %s: Compute factorial(%s)..." % (name, i)) @@ -150,25 +144,21 @@ from typing import Generator, Any import asyncio from asyncio import Future -@asyncio.coroutine -def h4() -> 'Generator[Any, None, int]': +async def h4() -> 'Generator[Any, None, int]': x = yield from future return x -@asyncio.coroutine -def h3() -> 'Generator[Any, None, int]': +async def h3() -> 'Generator[Any, None, int]': x = yield from h4() print("h3: %s" % x) return x -@asyncio.coroutine -def h2() -> 'Generator[Any, None, int]': +async def h2() -> 'Generator[Any, None, int]': x = yield from h3() print("h2: %s" % x) return x -@asyncio.coroutine -def h() -> 'Generator[Any, None, None]': +async def h() -> 'Generator[Any, None, None]': x = yield from h2() print("h: %s" % x) @@ -190,22 +180,19 @@ from typing import Generator, Any import asyncio from asyncio import Future -@asyncio.coroutine -def h4() -> 'Generator[Any, None, Future[int]]': +async def h4() -> 'Generator[Any, None, Future[int]]': yield from asyncio.sleep(0.1) f = asyncio.Future() #type: Future[int] return f -@asyncio.coroutine -def h3() -> 'Generator[Any, None, Future[Future[int]]]': +async def h3() -> 'Generator[Any, None, Future[Future[int]]]': x = yield from h4() x.set_result(42) f = asyncio.Future() #type: Future[Future[int]] f.set_result(x) return f -@asyncio.coroutine -def h() -> 'Generator[Any, None, None]': +async def h() -> 'Generator[Any, None, None]': print("Before") x = yield from h3() y = yield from x @@ -238,8 +225,7 @@ class A: def __init__(self, x: int) -> None: self.x = x -@asyncio.coroutine -def h() -> 'Generator[Any, None, None]': +async def h() -> 'Generator[Any, None, None]': x = yield from future print("h: %s" % x.x) @@ -261,13 +247,11 @@ from typing import Generator, Any import asyncio from asyncio import Future -@asyncio.coroutine -def greet() -> 'Generator[Any, None, None]': +async def greet() -> 'Generator[Any, None, None]': yield from asyncio.sleep(0.2) print('Hello World') -@asyncio.coroutine -def test() -> 'Generator[Any, None, None]': +async def test() -> 'Generator[Any, None, None]': yield from greet() x = yield from greet() # Error @@ -284,14 +268,12 @@ from typing import Generator, Any import asyncio from asyncio import Future -@asyncio.coroutine -def compute(x: int, y: int) -> 'Generator[Any, None, int]': +async def compute(x: int, y: int) -> 'Generator[Any, None, int]': print("Compute %s + %s ..." % (x, y)) yield from asyncio.sleep(0.1) return str(x + y) # Error -@asyncio.coroutine -def print_sum(x: int, y: int) -> 'Generator[Any, None, None]': +async def print_sum(x: int, y: int) -> 'Generator[Any, None, None]': result = yield from compute(x, y) print("%s + %s = %s" % (x, y, result)) @@ -307,8 +289,7 @@ from typing import Generator, Any import asyncio from asyncio import Future -@asyncio.coroutine -def slow_operation(future: 'Future[str]') -> 'Generator[Any, None, None]': +async def slow_operation(future: 'Future[str]') -> 'Generator[Any, None, None]': yield from asyncio.sleep(1) future.set_result(42) # Error @@ -327,8 +308,7 @@ from typing import Any, Generator import asyncio from asyncio import Future -@asyncio.coroutine -def slow_operation(future: 'Future[int]') -> 'Generator[Any, None, None]': +async def slow_operation(future: 'Future[int]') -> 'Generator[Any, None, None]': yield from asyncio.sleep(1) future.set_result(42) @@ -346,8 +326,7 @@ from typing import Generator, Any import asyncio from asyncio import Future -@asyncio.coroutine -def slow_operation(future: 'Future[int]') -> 'Generator[Any, None, None]': +async def slow_operation(future: 'Future[int]') -> 'Generator[Any, None, None]': yield from asyncio.sleep(1) future.set_result('42') #Try to set an str as result to a Future[int] @@ -367,8 +346,7 @@ from typing import Generator, Any import asyncio from asyncio import Future, AbstractEventLoop -@asyncio.coroutine -def slow_operation(future: 'Future[str]') -> 'Generator[Any, None, None]': +async def slow_operation(future: 'Future[str]') -> 'Generator[Any, None, None]': yield from asyncio.sleep(1) future.set_result('Future is done!') @@ -394,22 +372,19 @@ from typing import Any, Generator import asyncio from asyncio import Future -@asyncio.coroutine -def h4() -> 'Generator[Any, None, Future[int]]': +async def h4() -> 'Generator[Any, None, Future[int]]': yield from asyncio.sleep(1) f = asyncio.Future() #type: Future[int] return f -@asyncio.coroutine -def h3() -> 'Generator[Any, None, Future[Future[Future[int]]]]': +async def h3() -> 'Generator[Any, None, Future[Future[Future[int]]]]': x = yield from h4() x.set_result(42) f = asyncio.Future() #type: Future[Future[int]] f.set_result(x) return f -@asyncio.coroutine -def h() -> 'Generator[Any, None, None]': +async def h() -> 'Generator[Any, None, None]': print("Before") x = yield from h3() y = yield from x @@ -430,22 +405,19 @@ from typing import Any, Generator import asyncio from asyncio import Future -@asyncio.coroutine -def h4() -> 'Generator[Any, None, Future[int]]': +async def h4() -> 'Generator[Any, None, Future[int]]': yield from asyncio.sleep(1) f = asyncio.Future() #type: Future[int] return f -@asyncio.coroutine -def h3() -> 'Generator[Any, None, Future[int]]': +async def h3() -> 'Generator[Any, None, Future[int]]': x = yield from h4() x.set_result(42) f = asyncio.Future() #type: Future[Future[int]] f.set_result(x) return f -@asyncio.coroutine -def h() -> 'Generator[Any, None, None]': +async def h() -> 'Generator[Any, None, None]': print("Before") x = yield from h3() y = yield from x @@ -472,8 +444,7 @@ class B: def __init__(self, x: int) -> None: self.x = x -@asyncio.coroutine -def h() -> 'Generator[Any, None, None]': +async def h() -> 'Generator[Any, None, None]': x = yield from future # type: B # Error print("h: %s" % x.x) @@ -496,8 +467,7 @@ def test() -> None: reveal_type(bad) bad(0) -@asyncio.coroutine -def bad(arg: P) -> T: +async def bad(arg: P) -> T: pass [out] _program.py:8: note: Revealed type is "def [T] (arg: P?) -> T`-1" From bcb5ac466d470b1d7c1c983e7ad2f7a5f5f2f774 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Sat, 21 May 2022 23:05:10 -0700 Subject: [PATCH 2/6] fix tests --- test-data/unit/pythoneval-asyncio.test | 160 +++++++++++++------------ 1 file changed, 81 insertions(+), 79 deletions(-) diff --git a/test-data/unit/pythoneval-asyncio.test b/test-data/unit/pythoneval-asyncio.test index b3c587b51f57..75e8b610758b 100644 --- a/test-data/unit/pythoneval-asyncio.test +++ b/test-data/unit/pythoneval-asyncio.test @@ -4,7 +4,7 @@ -- These are mostly regression tests -- no attempt is made to make these -- complete. -- --- This test file check Asyncio and yield from interaction +-- This test file check Asyncio and await interaction [case testImportAsyncio] import asyncio @@ -17,11 +17,11 @@ from typing import Any, Generator import asyncio from asyncio import Future -async def greet_every_two_seconds() -> 'Generator[Any, None, None]': +async def greet_every_two_seconds() -> None: n = 0 while n < 5: print('Prev', n) - yield from asyncio.sleep(0.1) + await asyncio.sleep(0.01) print('After', n) n += 1 @@ -47,13 +47,13 @@ from typing import Generator, Any import asyncio from asyncio import Future -async def compute(x: int, y: int) -> 'Generator[Any, None, int]': +async def compute(x: int, y: int) -> int: print("Compute %s + %s ..." % (x, y)) - yield from asyncio.sleep(0.1) + await asyncio.sleep(0.01) return x + y # Here the int is wrapped in Future[int] -async def print_sum(x: int, y: int) -> 'Generator[Any, None, None]': - result = yield from compute(x, y) # The type of result will be int (is extracted from Future[int] +async def print_sum(x: int, y: int) -> None: + result = await compute(x, y) # The type of result will be int (is extracted from Future[int] print("%s + %s = %s" % (x, y, result)) loop = asyncio.get_event_loop() @@ -68,8 +68,8 @@ from typing import Generator, Any import asyncio from asyncio import Future -async def slow_operation(future: 'Future[str]') -> 'Generator[Any, None, None]': - yield from asyncio.sleep(0.1) +async def slow_operation(future: 'Future[str]') -> None: + await asyncio.sleep(0.01) future.set_result('Future is done!') loop = asyncio.get_event_loop() @@ -87,8 +87,8 @@ from typing import Generator, Any import asyncio from asyncio import Future, AbstractEventLoop -async def slow_operation(future: 'Future[str]') -> 'Generator[Any, None, None]': - yield from asyncio.sleep(1) +async def slow_operation(future: 'Future[str]') -> None: + await asyncio.sleep(1) future.set_result('Callback works!') def got_result(future: 'Future[str]') -> None: @@ -111,11 +111,11 @@ import typing from typing import Generator, Any import asyncio from asyncio import Task, Future -async def factorial(name, number) -> 'Generator[Any, None, None]': +async def factorial(name, number) -> None: f = 1 for i in range(2, number+1): print("Task %s: Compute factorial(%s)..." % (name, i)) - yield from asyncio.sleep(0.1) + await asyncio.sleep(0.01) f *= i print("Task %s: factorial(%s) = %s" % (name, number, f)) @@ -144,22 +144,22 @@ from typing import Generator, Any import asyncio from asyncio import Future -async def h4() -> 'Generator[Any, None, int]': - x = yield from future +async def h4() -> int: + x = await future return x -async def h3() -> 'Generator[Any, None, int]': - x = yield from h4() +async def h3() -> int: + x = await h4() print("h3: %s" % x) return x -async def h2() -> 'Generator[Any, None, int]': - x = yield from h3() +async def h2() -> int: + x = await h3() print("h2: %s" % x) return x -async def h() -> 'Generator[Any, None, None]': - x = yield from h2() +async def h() -> None: + x = await h2() print("h: %s" % x) loop = asyncio.get_event_loop() @@ -180,23 +180,23 @@ from typing import Generator, Any import asyncio from asyncio import Future -async def h4() -> 'Generator[Any, None, Future[int]]': - yield from asyncio.sleep(0.1) +async def h4() -> Future[int]: + await asyncio.sleep(0.01) f = asyncio.Future() #type: Future[int] return f -async def h3() -> 'Generator[Any, None, Future[Future[int]]]': - x = yield from h4() +async def h3() -> Future[Future[int]]: + x = await h4() x.set_result(42) f = asyncio.Future() #type: Future[Future[int]] f.set_result(x) return f -async def h() -> 'Generator[Any, None, None]': +async def h() -> None: print("Before") - x = yield from h3() - y = yield from x - z = yield from y + x = await h3() + y = await x + z = await y print(z) def normalize(future): # The str conversion seems inconsistent; not sure exactly why. Normalize @@ -225,8 +225,8 @@ class A: def __init__(self, x: int) -> None: self.x = x -async def h() -> 'Generator[Any, None, None]': - x = yield from future +async def h() -> None: + x = await future print("h: %s" % x.x) loop = asyncio.get_event_loop() @@ -247,13 +247,13 @@ from typing import Generator, Any import asyncio from asyncio import Future -async def greet() -> 'Generator[Any, None, None]': - yield from asyncio.sleep(0.2) +async def greet() -> None: + await asyncio.sleep(0.2) print('Hello World') -async def test() -> 'Generator[Any, None, None]': - yield from greet() - x = yield from greet() # Error +async def test() -> None: + await greet() + x = await greet() # Error loop = asyncio.get_event_loop() try: @@ -264,17 +264,17 @@ finally: _program.py:13: error: Function does not return a value [case testErrorReturnIsNotTheSameType] -from typing import Generator, Any +from typing import Any import asyncio from asyncio import Future -async def compute(x: int, y: int) -> 'Generator[Any, None, int]': +async def compute(x: int, y: int) -> int: print("Compute %s + %s ..." % (x, y)) - yield from asyncio.sleep(0.1) + await asyncio.sleep(0.01) return str(x + y) # Error -async def print_sum(x: int, y: int) -> 'Generator[Any, None, None]': - result = yield from compute(x, y) +async def print_sum(x: int, y: int) -> None: + result = await compute(x, y) print("%s + %s = %s" % (x, y, result)) loop = asyncio.get_event_loop() @@ -282,15 +282,15 @@ loop.run_until_complete(print_sum(1, 2)) loop.close() [out] -_program.py:9: error: Incompatible return value type (got "str", expected "int") +_program.py:8: error: Incompatible return value type (got "str", expected "int") [case testErrorSetFutureDifferentInternalType] from typing import Generator, Any import asyncio from asyncio import Future -async def slow_operation(future: 'Future[str]') -> 'Generator[Any, None, None]': - yield from asyncio.sleep(1) +async def slow_operation(future: 'Future[str]') -> None: + await asyncio.sleep(1) future.set_result(42) # Error loop = asyncio.get_event_loop() @@ -300,7 +300,7 @@ loop.run_until_complete(future) print(future.result()) loop.close() [out] -_program.py:8: error: Argument 1 to "set_result" of "Future" has incompatible type "int"; expected "str" +_program.py:7: error: Argument 1 to "set_result" of "Future" has incompatible type "int"; expected "str" [case testErrorUsingDifferentFutureType] @@ -308,8 +308,8 @@ from typing import Any, Generator import asyncio from asyncio import Future -async def slow_operation(future: 'Future[int]') -> 'Generator[Any, None, None]': - yield from asyncio.sleep(1) +async def slow_operation(future: 'Future[int]') -> None: + await asyncio.sleep(1) future.set_result(42) loop = asyncio.get_event_loop() @@ -319,15 +319,15 @@ loop.run_until_complete(future) print(future.result()) loop.close() [out] -_program.py:12: error: Argument 1 to "slow_operation" has incompatible type "Future[str]"; expected "Future[int]" +_program.py:11: error: Argument 1 to "slow_operation" has incompatible type "Future[str]"; expected "Future[int]" [case testErrorUsingDifferentFutureTypeAndSetFutureDifferentInternalType] from typing import Generator, Any import asyncio from asyncio import Future -async def slow_operation(future: 'Future[int]') -> 'Generator[Any, None, None]': - yield from asyncio.sleep(1) +async def slow_operation(future: 'Future[int]') -> None: + await asyncio.sleep(1) future.set_result('42') #Try to set an str as result to a Future[int] loop = asyncio.get_event_loop() @@ -337,8 +337,8 @@ loop.run_until_complete(future) print(future.result()) loop.close() [out] -_program.py:8: error: Argument 1 to "set_result" of "Future" has incompatible type "str"; expected "int" -_program.py:12: error: Argument 1 to "slow_operation" has incompatible type "Future[str]"; expected "Future[int]" +_program.py:7: error: Argument 1 to "set_result" of "Future" has incompatible type "str"; expected "int" +_program.py:11: error: Argument 1 to "slow_operation" has incompatible type "Future[str]"; expected "Future[int]" [case testErrorSettingCallbackWithDifferentFutureType] import typing @@ -346,8 +346,8 @@ from typing import Generator, Any import asyncio from asyncio import Future, AbstractEventLoop -async def slow_operation(future: 'Future[str]') -> 'Generator[Any, None, None]': - yield from asyncio.sleep(1) +async def slow_operation(future: 'Future[str]') -> None: + await asyncio.sleep(1) future.set_result('Future is done!') def got_result(future: 'Future[int]') -> None: @@ -364,7 +364,7 @@ try: finally: loop.close() [out] -_program.py:18: error: Argument 1 to "add_done_callback" of "Future" has incompatible type "Callable[[Future[int]], None]"; expected "Callable[[Future[str]], Any]" +_program.py:17: error: Argument 1 to "add_done_callback" of "Future" has incompatible type "Callable[[Future[int]], None]"; expected "Callable[[Future[str]], Any]" [case testErrorOneMoreFutureInReturnType] import typing @@ -372,23 +372,23 @@ from typing import Any, Generator import asyncio from asyncio import Future -async def h4() -> 'Generator[Any, None, Future[int]]': - yield from asyncio.sleep(1) +async def h4() -> Future[int]: + await asyncio.sleep(1) f = asyncio.Future() #type: Future[int] return f -async def h3() -> 'Generator[Any, None, Future[Future[Future[int]]]]': - x = yield from h4() +async def h3() -> Future[Future[Future[int]]]: + x = await h4() x.set_result(42) f = asyncio.Future() #type: Future[Future[int]] f.set_result(x) return f -async def h() -> 'Generator[Any, None, None]': +async def h() -> None: print("Before") - x = yield from h3() - y = yield from x - z = yield from y + x = await h3() + y = await x + z = await y print(z) print(y) print(x) @@ -397,30 +397,30 @@ loop = asyncio.get_event_loop() loop.run_until_complete(h()) loop.close() [out] -_program.py:18: error: Incompatible return value type (got "Future[Future[int]]", expected "Future[Future[Future[int]]]") +_program.py:16: error: Incompatible return value type (got "Future[Future[int]]", expected "Future[Future[Future[int]]]") [case testErrorOneLessFutureInReturnType] import typing -from typing import Any, Generator +from typing import Any import asyncio from asyncio import Future -async def h4() -> 'Generator[Any, None, Future[int]]': - yield from asyncio.sleep(1) +async def h4() -> Future[int]: + await asyncio.sleep(1) f = asyncio.Future() #type: Future[int] return f -async def h3() -> 'Generator[Any, None, Future[int]]': - x = yield from h4() +async def h3() -> Future[int]: + x = await h4() x.set_result(42) f = asyncio.Future() #type: Future[Future[int]] f.set_result(x) return f -async def h() -> 'Generator[Any, None, None]': +async def h() -> None: print("Before") - x = yield from h3() - y = yield from x + x = await h3() + y = await x print(y) print(x) @@ -428,7 +428,7 @@ loop = asyncio.get_event_loop() loop.run_until_complete(h()) loop.close() [out] -_program.py:18: error: Incompatible return value type (got "Future[Future[int]]", expected "Future[int]") +_program.py:16: error: Incompatible return value type (got "Future[Future[int]]", expected "Future[int]") [case testErrorAssignmentDifferentType] import typing @@ -444,8 +444,8 @@ class B: def __init__(self, x: int) -> None: self.x = x -async def h() -> 'Generator[Any, None, None]': - x = yield from future # type: B # Error +async def h() -> None: + x = await future # type: B # Error print("h: %s" % x.x) loop = asyncio.get_event_loop() @@ -454,7 +454,7 @@ future.set_result(A(42)) loop.run_until_complete(h()) loop.close() [out] -_program.py:16: error: Incompatible types in assignment (expression has type "A", variable has type "B") +_program.py:15: error: Incompatible types in assignment (expression has type "A", variable has type "B") [case testForwardRefToBadAsyncShouldNotCrash_newsemanal] from typing import TypeVar @@ -470,6 +470,8 @@ def test() -> None: async def bad(arg: P) -> T: pass [out] -_program.py:8: note: Revealed type is "def [T] (arg: P?) -> T`-1" -_program.py:12: error: Variable "_testForwardRefToBadAsyncShouldNotCrash_newsemanal.P" is not valid as a type -_program.py:12: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases +_program.py:8: note: Revealed type is "def [T] (arg: P?) -> typing.Coroutine[Any, Any, T`-1]" +_program.py:9: error: Value of type "Coroutine[Any, Any, ]" must be used +_program.py:9: note: Are you missing an await? +_program.py:11: error: Variable "_testForwardRefToBadAsyncShouldNotCrash_newsemanal.P" is not valid as a type +_program.py:11: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases From aa24245b99d8b3f9311fa6311e88fe07431b0557 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Sat, 21 May 2022 23:32:20 -0700 Subject: [PATCH 3/6] mark a test as xfail --- test-data/unit/pythoneval-asyncio.test | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test-data/unit/pythoneval-asyncio.test b/test-data/unit/pythoneval-asyncio.test index 75e8b610758b..44d681c25c8e 100644 --- a/test-data/unit/pythoneval-asyncio.test +++ b/test-data/unit/pythoneval-asyncio.test @@ -242,7 +242,8 @@ Outside 42 -- Errors -[case testErrorAssigningCoroutineThatDontReturn] +[case testErrorAssigningCoroutineThatDontReturn-xfail] +# https://github.com/python/mypy/issues/12837 from typing import Generator, Any import asyncio from asyncio import Future From e2455db7cd4e8306de761dc0d6e1bbff0faeb151 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Sun, 22 May 2022 00:12:04 -0700 Subject: [PATCH 4/6] quotes for the executed test --- test-data/unit/pythoneval-asyncio.test | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test-data/unit/pythoneval-asyncio.test b/test-data/unit/pythoneval-asyncio.test index 44d681c25c8e..5119e5f13a7b 100644 --- a/test-data/unit/pythoneval-asyncio.test +++ b/test-data/unit/pythoneval-asyncio.test @@ -180,12 +180,12 @@ from typing import Generator, Any import asyncio from asyncio import Future -async def h4() -> Future[int]: +async def h4() -> "Future[int]": await asyncio.sleep(0.01) f = asyncio.Future() #type: Future[int] return f -async def h3() -> Future[Future[int]]: +async def h3() -> "Future[Future[int]]": x = await h4() x.set_result(42) f = asyncio.Future() #type: Future[Future[int]] From a4439f2c352b38b5ee30d50292a56520db8af515 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Sun, 22 May 2022 00:13:18 -0700 Subject: [PATCH 5/6] also remove unused imports --- test-data/unit/pythoneval-asyncio.test | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/test-data/unit/pythoneval-asyncio.test b/test-data/unit/pythoneval-asyncio.test index 5119e5f13a7b..067d95f99c88 100644 --- a/test-data/unit/pythoneval-asyncio.test +++ b/test-data/unit/pythoneval-asyncio.test @@ -43,7 +43,7 @@ Prev 4 After 4 [case testCoroutineCallingOtherCoroutine] -from typing import Generator, Any +from typing import Any import asyncio from asyncio import Future @@ -64,7 +64,7 @@ Compute 1 + 2 ... 1 + 2 = 3 [case testCoroutineChangingFuture] -from typing import Generator, Any +from typing import Any import asyncio from asyncio import Future @@ -83,7 +83,7 @@ Future is done! [case testFunctionAssignedAsCallback] import typing -from typing import Generator, Any +from typing import Any import asyncio from asyncio import Future, AbstractEventLoop @@ -108,7 +108,7 @@ Callback works! [case testMultipleTasks] import typing -from typing import Generator, Any +from typing import Any import asyncio from asyncio import Task, Future async def factorial(name, number) -> None: @@ -140,7 +140,7 @@ Task C: factorial(4) = 24 [case testConcatenatedCoroutines] import typing -from typing import Generator, Any +from typing import Any import asyncio from asyncio import Future @@ -176,7 +176,7 @@ Outside 42 [case testConcatenatedCoroutinesReturningFutures] import typing -from typing import Generator, Any +from typing import Any import asyncio from asyncio import Future @@ -217,7 +217,7 @@ Future> [case testCoroutineWithOwnClass] import typing -from typing import Generator, Any +from typing import Any import asyncio from asyncio import Future @@ -244,7 +244,7 @@ Outside 42 [case testErrorAssigningCoroutineThatDontReturn-xfail] # https://github.com/python/mypy/issues/12837 -from typing import Generator, Any +from typing import Any import asyncio from asyncio import Future @@ -286,7 +286,7 @@ loop.close() _program.py:8: error: Incompatible return value type (got "str", expected "int") [case testErrorSetFutureDifferentInternalType] -from typing import Generator, Any +from typing import Any import asyncio from asyncio import Future @@ -305,7 +305,7 @@ _program.py:7: error: Argument 1 to "set_result" of "Future" has incompatible ty [case testErrorUsingDifferentFutureType] -from typing import Any, Generator +from typing import Any import asyncio from asyncio import Future @@ -323,7 +323,7 @@ loop.close() _program.py:11: error: Argument 1 to "slow_operation" has incompatible type "Future[str]"; expected "Future[int]" [case testErrorUsingDifferentFutureTypeAndSetFutureDifferentInternalType] -from typing import Generator, Any +from typing import Any import asyncio from asyncio import Future @@ -343,7 +343,7 @@ _program.py:11: error: Argument 1 to "slow_operation" has incompatible type "Fut [case testErrorSettingCallbackWithDifferentFutureType] import typing -from typing import Generator, Any +from typing import Any import asyncio from asyncio import Future, AbstractEventLoop @@ -433,7 +433,7 @@ _program.py:16: error: Incompatible return value type (got "Future[Future[int]]" [case testErrorAssignmentDifferentType] import typing -from typing import Generator, Any +from typing import Any import asyncio from asyncio import Future From d1685fd9337d8913ffaba1dbff098d14e6843dfa Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Sun, 22 May 2022 15:38:53 -0700 Subject: [PATCH 6/6] Update test-data/unit/pythoneval-asyncio.test Co-authored-by: Alex Waygood --- test-data/unit/pythoneval-asyncio.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-data/unit/pythoneval-asyncio.test b/test-data/unit/pythoneval-asyncio.test index 067d95f99c88..11a61756a824 100644 --- a/test-data/unit/pythoneval-asyncio.test +++ b/test-data/unit/pythoneval-asyncio.test @@ -4,7 +4,7 @@ -- These are mostly regression tests -- no attempt is made to make these -- complete. -- --- This test file check Asyncio and await interaction +-- This test file checks Asyncio and await interaction [case testImportAsyncio] import asyncio