python / python/cpython

typing._allow_reckless_class_checks doesn't work when _abc doesn't exist.

未关闭
#136,047 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

topic-typing type-bug
主要语言
Python
星标
77.2k
派生
36k
PR 合并指标
PR 指标待抓取

描述

Bug report

Bug description:

When typing._caller's sys._getframe fallback is triggered without _abc module, _typing._allow_reckless_class_checks fails to check _py_abc while running abc.ABCMeta.__instancecheck__.

Without _abc module, _typing._allow_reckless_class_checksfails to check _py_abc

Related code in typing.py:
https://github.com/python/cpython/blob/v3.14.0b3/Lib/typing.py#L1846-L1863

This is technically a bug of typing.py, but really hard to be triggered on CPython.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Solution suggestion

Patch typing._allow_reckless_class_checks to also check _py_abc

This is the most conservative approach. Compatible with all of previous scenarios and additionally fixing the bug.

Patch typing._caller to remove sys._getframe or raise warning when fallback

If the the typing requires to work with sys._getframemodulename, then let the users to know it has a caveat.

Linked PRs
  • gh-136115

贡献指南

打开贡献指南

从这里开始

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

调研方向

阅读 Lib/typing.py 的第 1846-1863 行,并将提议的更改与链接的 PR gh-136115 进行比较。当 _abc 不可用时,_allow_reckless_class_checks 也能处理 _py_abc,并且已在 CPython main 分支上验证其行为,即表示完成。

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

评估

技术栈
python
领域
backend
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
描述清楚
新手友好度
25/100

把新 issue 发到你的邮箱

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