Skip to content

Preserve task types in asyncio.as_completed - #16449

Open
jw9829 wants to merge 1 commit into
python:mainfrom
jw9829:fix-as-completed-task-preservation-15644
Open

jw9829 wants to merge 1 commit into
python:mainfrom
jw9829:fix-as-completed-task-preservation-15644

Conversation

@jw9829

@jw9829 jw9829 commented Sep 28, 2026

Copy link
Copy Markdown

Fixes #15644. When as_completed() receives tasks, async iteration now preserves their Task[T] type instead of widening them to Future[T]. Regular iteration continues to yield coroutines.

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

async-utils (https://github.com/mikeshardmind/async-utils)
+ src/async_utils/_merge_gens.py:211: error: Argument 2 to "anext" has incompatible type "Task[T] | None"; expected "T"  [arg-type]
+ src/async_utils/_merge_gens.py:262: error: Argument 2 to "anext" has incompatible type "Task[T] | None"; expected "T"  [arg-type]
+ src/async_utils/_merge_gens.py:314: error: Argument 2 to "anext" has incompatible type "Task[T] | None"; expected "T"  [arg-type]
- error: INTERNAL ERROR -- Please try using mypy master on GitHub:
- https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
- Please report a bug at https://github.com/python/mypy/issues
- version: 2.3.0
- note: use --pdb to drop into pdb
- Traceback (most recent call last):
-   File "/__main__.py", line 16, in console_entry
-     main()
-     ~~~~^^
-   File "mypy/main.py", line 154, in main
-   File "mypy/main.py", line 244, in run_build
-     res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
-   File "mypy/build.py", line 385, in build
-   File "mypy/build.py", line 1908, in create_metastore
-     mds: MetadataStore = SqliteMetadataStore(
-   File "mypy/metastore.py", line 200, in __init__
-   File "mypy/metastore.py", line 174, in connect_db
-     db.execute("PRAGMA journal_mode=WAL")
- sqlite3.OperationalError: database is locked
- 

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

asyncio.as_completed as async iterator can yield tasks as well as futures

1 participant