Type Checking for Class Row Factory
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 20/100
Research direction
Review Issue #42 and PR #57 first, since the proposed solution is described there. Then inspect comdb2.dataclasses.class_row_factory and compare the BaseRowFactoryClass example with the stated type-checking concern. Done means confirming whether the PR fully addresses validation for dataclass attributes and database output.
Written by the indexing model from the issue text.
Description
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)
- Dominant language
- Python
- Stars
- 29
- Forks
- 28
- Avg merge
- 11h 25m
- Merged PRs (30d)
- 2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from bloomberg/python-comdb2
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
bloomberg/python-comdb2#80 ·
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 25/100
bloomberg/python-comdb2#61 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
bloomberg/python-comdb2#42 · 14 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
bloomberg/python-comdb2#41 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
bloomberg/python-comdb2#36 · 1 comment ·
All issues in bloomberg/python-comdb2
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
learningequality/ricecooker#747 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
BSData/horus-heresy-3rd-edition#3171 ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
run-llama/llama_index#23199 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
KhronosGroup/glTF-Blender-IO#2769 ·