danielgtaylor / danielgtaylor/python-betterproto

datetime support in .from_dict()

オープン
#33 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug good first issue low priority small
主要言語
Python
スター
1.8k
フォーク
234
PR マージ指標
30日以内にマージされた PR はありません

説明

Good day, assuming I have
`d = {'date_of_birth': datetime.datetime(2000)}`
and a `proto` including
`date_of_birth: Timestamp`:
When `proto.from_dict(d)` is called, it assumes the value of date_of_birth is an ISO string and does not consider that it may already be a `datetime.datetime`

I refer to your `__init__.py` L799-803:
```
elif isinstance(v, datetime):
v = datetime.fromisoformat(
value[key].replace("Z", "+00:00")
)
setattr(self, field.name, v)
```
This should check if `value[key]` is already an instance of `datetime.datetime` and assign it directly, shouldn't it?

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

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

調査の方向性

__init__.py の 799-803 行付近から始め、Timestamp フィールドに対する .from_dict() の処理を追跡してください。既存の datetime.datetime 値と ISO 形式の文字列の両方について動作を確認します。datetime 入力が文字列変換なしで代入され、文字列入力が現在の解析動作を維持していれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
35/100

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

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