-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Change create_task
type
#6779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change create_task
type
#6779
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import concurrent.futures | |
import sys | ||
from collections.abc import Awaitable, Generator, Iterable, Iterator | ||
from types import FrameType | ||
from typing import Any, Generic, Optional, TextIO, TypeVar, Union, overload | ||
from typing import Any, Coroutine, Generic, Optional, TextIO, TypeVar, Union, overload | ||
from typing_extensions import Literal | ||
|
||
from .events import AbstractEventLoop | ||
|
@@ -289,9 +289,9 @@ class Task(Future[_T], Generic[_T]): | |
if sys.version_info >= (3, 7): | ||
def all_tasks(loop: AbstractEventLoop | None = ...) -> set[Task[Any]]: ... | ||
if sys.version_info >= (3, 8): | ||
def create_task(coro: Generator[_TaskYieldType, None, _T] | Awaitable[_T], *, name: str | None = ...) -> Task[_T]: ... | ||
def create_task(coro: Generator[Any, None, _T] | Coroutine[Any, Any, _T], *, name: str | None = ...) -> Task[_T]: ... | ||
else: | ||
def create_task(coro: Generator[_TaskYieldType, None, _T] | Awaitable[_T]) -> Task[_T]: ... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Notice that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't seem right. Event loops typically use yields to communicate between tasks and the loop, so the generator must yield objects of a specific type. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some experiments: import asyncio
def gen():
i = yield
print(1, i) # prints: `1, None`
return 'a'
async def main():
print('res', await asyncio.create_task(gen())) # prints: `res, a`
asyncio.run(main()) And: import asyncio
def gen():
i = yield
print(1, i) # prints: `1, None`
yield 'a'
async def main():
print('res', await asyncio.create_task(gen()))
asyncio.run(main())
|
||
def create_task(coro: Generator[Any, None, _T] | Coroutine[Any, Any, _T]) -> Task[_T]: ... | ||
|
||
def current_task(loop: AbstractEventLoop | None = ...) -> Task[Any] | None: ... | ||
def _enter_task(loop: AbstractEventLoop, task: Task[Any]) -> None: ... | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit for future reference:
Coroutine
should now be imported fromcollections.abc
.