Consistent interface to get text and bytes
未关闭
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 1.7k
- 派生
- 408
- 平均合并
- 2 天 57 分钟
- 30 天内合并 PR
- 7
描述
Follow up from #610 #790 and #893
General policy:
- Do not implement
str() - To get unicode string use
.text - In
.textuse UTF-8 and replace (the rationale for replace is explained in https://github.com/libgit2/pygit2/pull/790#issuecomment-385906316) - To get the byte string use
.dataor.raw(this is to be decided) - For attributes the name of the attribute returns text, prefix with
raw_to get bytes. For instanceSignature.nameandSignature.raw_name - Implement the buffer protocol,
bytes(..)where appropriate
Open for discussion.
TODO:
- Replace
TreeEntry._nameby.raw_name - Replace
DiffLine.contentby.text - Inventory all the places where we get bytes, text, or the buffer protocol
- Settle on
.dataor.raw - Replace
DiffLine.raw_contentby.dataor.raw - Replace
Object.read_raw()by.data(or.raw), then removeBlob.data(it will inherit fromObject) - Settle on
str()bytes()and the buffer protocol
The case of Oid, what we've now:
oid.rawreturns the byte string (that's good, unless we decide to settle on.data)str(oid)andoid.hexboth return the hex representation, always<str>(bytes in Python 2 and text in Python 3)- Oid is the only place where we implement
str(...) Object.hexandTreeEntry.hexbehave the same, they return always<str>. Apparently these are the only places where we always return<str>.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先查看关联的 issues #610、#790 和 #893,然后盘点此处描述的当前 Oid、Object、TreeEntry 和 DiffLine 接口。要视为完成,必须确定 text/bytes 的命名和转换策略,并在所有 bindings 中一致地解决所列出的 TODO。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- git, python
- 领域
- api, backend-api-design, tooling
- Issue 类型
- 重构
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 20/100