Type Checking for Class Row Factory
还没有人认领这个 Issue。
评估
调研方向
首先查看 Issue #42 和 PR #57,因为其中描述了所提议的解决方案。然后检查 comdb2.dataclasses.class_row_factory,并将 BaseRowFactoryClass 示例与所述的类型检查问题进行比较。完成的标准是确认 PR 是否完全解决了 dataclass 属性和数据库输出的验证问题。
由索引模型根据 Issue 内容生成。
描述
As described in Issue #42 there was a proposed solution for having a Class Row Factory. Alongside the conversations happened there, there was a concern regarding type checking for the attributes of the class and output returned by the database. There doesn't seem to be a way to enforce type checking hence an extra __post_init__ method would be required within the class to enforce type checking. This can be overlooked by a lot of developers and can lead to a lot of type mismatches.
Solution
Define a Base class that our dataclasses can inherit. The Base class can have all the required methods for the validation etc.
The updated use of it can be described it here. The solution has been implemented on the PR #57
>>> from dataclasses import dataclass
>>> from comdb2.dataclasses.class_row_factory import BaseRowFactoryClass
...
>>> @dataclass
>>> class ABC(BaseRowFactoryClass):
>>> x: int
>>> y: int
...
>>> conn.row_factory = ClassRowFactory(ABC)
>>> row = conn.cursor().execute("select 1 as x, 2 as y").fetchone()
>>> print(row)
<>
>>> print(row.x)
- 主要语言
- Python
- 星标
- 29
- 派生
- 28
- 平均合并
- 11 小时 25 分钟
- 30 天内合并 PR
- 2
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
bloomberg/python-comdb2 的其他 Issue
-
enhancement
难度 5/5 一周以上 新手友好度 25/100
bloomberg/python-comdb2#61 ·
-
难度 4/5 3-5 天 新手友好度 25/100
bloomberg/python-comdb2#42 · 14 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 35/100
bloomberg/python-comdb2#41 ·
-
难度 4/5 3-5 天 新手友好度 35/100
bloomberg/python-comdb2#36 · 1 条评论 ·
查看 bloomberg/python-comdb2 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 86/100
browser-use/browser-use#5905 ·
-
type: enhancement
难度 2/5 1-3 小时 新手友好度 68/100
ynput/ayon-python-api#363 ·
-
bug needs triage
难度 2/5 1-3 小时 新手友好度 88/100
modelscope/FunASR#3728 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
open-compass/opencompass#2655 ·