Type hint asyncio.Process streams (stdin, stdout, stderr) when created with values other than default None
Open
Nobody has claimed this yet.
stubs: false positive
- Dominant language
- Python
- Stars
- 5.1k
- Forks
- 2.1k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 82
Description
Is it possible to update asyncio stub files so that asyncio.Process.{stdin,stdout,stderr} are resolved as non-None by mypy?
Example:
from asyncio import create_subprocess_exec
from asyncio.subprocess import PIPE
async def main() -> None:
proc = await create_subprocess_exec('/usr/bin/ls', stdout=PIPE)
async for line in proc.stdout:
print(line)
Typing error reported by mypy (desired behaviour is no error):
error: Item "None" of "StreamReader | None" has no attribute "__aiter__" (not async iterable) [union-attr]
Current asyncio.Process declaration in typeshed/stdlib/asyncio/subprocess.pyi:
class Process:
stdin: streams.StreamWriter | None
stdout: streams.StreamReader | None
stderr: streams.StreamReader | None
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 Process declaration in typeshed/stdlib/asyncio/subprocess.pyi and trace the asyncio subprocess declarations used by create_subprocess_exec. Reproduce the mypy error from the issue's example, then verify that passing PIPE makes the relevant stream attributes non-optional without changing the default None behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- developer-experience
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100