`asyncio.gather` is sometimes erroneously type-checked
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
I'm adding typing to a large codebase, and have noticed weird asyncio.gather behavior.
To Reproduce
Here's a self-contained test:
from asyncio import gather
async def returns_dict() -> dict:
return {}
async def returns_int() -> int:
return 1
async def test():
tasks = (returns_dict(), returns_int())
reveal_type(await gather(*tasks)) # note: Revealed type is "Any"
Expected Behavior
The revealed type should be: note: Revealed type is "Tuple[builtins.dict*[Any, Any], builtins.int*]"
Actual Behavior
The correct return type is not recognized.
If the example is slightly changed:
from asyncio import gather
async def returns_dict() -> dict:
return {}
async def returns_int() -> int:
return 1
async def test():
reveal_type(await gather(returns_dict(), returns_int()))
it works properly.
Your Environment
- Mypy version used: 0.902
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): allow_redefinition, check_untyped_defs, namespace_packages, warn_unreachable - Python version used: 3.9.5
- Operating system and version: macOs Big Sur
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the self-contained asyncio.gather reproducer in the issue and compare the revealed types for a tuple passed with *tasks versus direct arguments. Trace the type-checking entry point for gather calls; done when the tuple form reveals the expected dict-and-int result instead of Any, with the existing direct-argument behavior preserved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100