python / python/typeshed

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

未关闭
#13,714 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

stubs: false positive
主要语言
Python
星标
5.1k
派生
2.1k
平均合并
1 天 19 小时
30 天内合并 PR
82

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 typeshed/stdlib/asyncio/subprocess.pyi 中的 Process 声明开始,跟踪 create_subprocess_exec 使用的 asyncio 子进程声明。重现 issue 示例中的 mypy 错误,然后验证传入 PIPE 会使相关的流属性变为非可选,同时不改变默认的 None 行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
developer-experience
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。