Better `repr` for `string.templatelib.Template`.
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Feature or enhancement
Proposal:
Currently the repr output for template strings shows how the data is stored internally, but this is not how the template could be reconstructed via an constructor call and the format is unintuitive since the template parts are not output in the order they appear in the template source. The repr result should output the parts in the order as iterating over the template object does, i.e.
x = 1
y = 2
print(repr(t'{x} + {y}'))
should print
Template(Interpolation(1, 'x', None, ''), ' + ', Interpolation(2, 'y', None, ''))
instead of
Template(strings=('', ' + ', ''), interpolations=(Interpolation(1, 'x', None, ''), Interpolation(2, 'y', None, '')))
This has already been discussed at https://discuss.python.org/t/repr-output-of-t-strings/107653
I'm working on a patch/pull request.
Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Links to previous discussion of this feature:
https://discuss.python.org/t/repr-output-of-t-strings/107653
Linked PRs
- gh-151104
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 issue 中描述的 string.templatelib.Template 的 repr 行为开始,并将其与遍历 template 对象进行比较。验证 repr 是否按迭代顺序输出 Template 部分,并与提议的构造函数调用格式匹配;gh-151104 已关联,因此在开始之前先审查该工作。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend
- Issue 类型
- 功能
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 25/100