Type Checking for Class Row Factory

オープン
#60 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
20/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python
領域
databases

調査の方向性

まず 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分
マージ済み PR(30日)
2

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

bloomberg/python-comdb2 のほかの issue

bloomberg/python-comdb2 の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。