Add stubs for stdlib `_colorize` module
还没有人认领这个 Issue。
评估
调研方向
首先阅读 CPython 的 Lib/_colorize.py,并将其中的类型化定义与 typeshed 中的标准库存根进行比较。使用 pyright、pyrefly 和 ty 检查提供的 reveal_type 示例;当 _colorize 的名称和签名能够被一致地识别且没有错误时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Description
_colorize was introduced in 3.13, and has been steadily growing since then.
From (https://github.com/python/cpython/issues/133346), I got the impression that the naming is due to unfortunate timing:
Rename
_colorizetocolorizeThere's frankly very little time for this before Python 3.14 beta 1. I would rather keep the library name underscored for 3.14 and gather feedback from the community on the format and behavior, and introduce a stable API in Python 3.15, keeping
_colorizefor backward compatibility.
Interestingly, _colorize is already fully-typed (https://github.com/python/cpython/blob/main/Lib/_colorize.py).
I'm here because the absence in _typeshed means this example [^1] can produce errors in some type checkers:
[^1]: Adapted from a comment in _colorize
from typing import reveal_type
try:
from _colorize import ANSIColors, Syntax, default_theme, set_theme
except ImportError:
pass
else:
reveal_type(set_theme)
theme_with_dim_operators = default_theme.copy_with(syntax=Syntax(op=ANSIColors.INTENSE_BLACK))
set_theme(theme_with_dim_operators)
del set_theme, default_theme, Syntax, ANSIColors, theme_with_dim_operators
This checks out fine with pyright, but both pyrefly and ty seem to not know about _colorize yet.
Perhaps adding to typeshed would help?
Related
- 主要语言
- Python
- 星标
- 5.1k
- 派生
- 2.1k
- 平均合并
- 1 天 13 小时
- 30 天内合并 PR
- 73
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python/typeshed 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
-
难度 2/5 1-3 小时 新手友好度 76/100
-
project: infrastructure
难度 2/5 1-3 小时 新手友好度 68/100
-
stubs: improvement
难度 2/5 1-3 小时 新手友好度 72/100
-
stubs: improvement
难度 2/5 1-3 小时 新手友好度 64/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
难度 2/5 1-3 小时 新手友好度 88/100
OpenHands/extensions#626 · 1 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 90/100
CSCfi/sd-search-api#39 ·
-
难度 1/5 1 小时以内 新手友好度 90/100
-
难度 2/5 1-3 小时 新手友好度 68/100
StevenBlack/hosts#3255 ·