python / python/typeshed

Safer types for datetime

オープン
#14,999 コメント 3 件 リアクション 1 件 担当者 0 名 GitHub で見る

@srittau がすでに取り組んでいます。

2024年4月29日 から。

  • #11844 @srittau による — オープン
主要言語
Python
スター
5.1k
フォーク
2.1k
平均マージ
1日 19時間
マージ済み PR(30日)
82

説明

At Dropbox we are currently debating what to do with the deprecation of datetime.utcnow from cpython upstream.

This deprecation is problematic because adjusting a single datetime to timezone-aware breaks its interoperability with other datetimes across the codebase. We have several thousand calls to datetime.utcnow and I am sure we are not the only ones in this situation.

It seems to me that in order to use timezone aware datetimes there is a need for these two different categories of datetimes to be separated on the type level. Perhaps this could be a generic argument with two possible parameters. I thought about suggesting it to the mypy repository, but I think perhaps it makes more sense to discuss this at typeshed, but I could be wrong. On the other hand, making the type generic is also a large breaking change in itself, which may not be desirable.

Without such type level distinction, I don't see how any large codebase can properly remove utcnow - the other option we are considering is to mass replace every callsite and use replace(tzinfo=None) which just makes the codebase worse than before - and perhaps dangerous if anyone starts creating timezone aware datetimes once utcnow is gone.

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

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

はじめの一歩

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

調査の方向性

datetime.utcnow の非推奨化に関する議論と、リンクされている pull request #11844 から始めてください。typeshed が naive と timezone-aware datetimes を別個の型として表現すべきかを明確にし、その後、実装前に影響を受けるスタブと型チェックの動作を定義してください。

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

評価

技術スタック
python
領域
tooling
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

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

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