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

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

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

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

描述

stubs: false positive

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
主要语言
Python
星标
5.1k
派生
2.1k
平均合并
2 天 1 小时
30 天内合并 PR
115

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

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

python/typeshed 的其他 Issue

查看 python/typeshed 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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