Skip to content

Type hint asyncio.Process streams (stdin, stdout, stderr) when created with values other than default None #13714

Open
@makukha

Description

@makukha

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions