unexpected behavior of `datetime.astimezone` method
オープン
まだ誰も着手していません。
3.12
3.13
3.14
extension-modules
stdlib
type-bug
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Bug report
Bug description:
my system time zone is UTC+04:00
>>> import datetime
>>> datetime.datetime(9999, 12, 31).astimezone() # same for .astimezone(datetime.UTC)
Traceback (most recent call last):
File "<python-input-46>", line 1, in <module>
datetime.datetime(9999, 12, 31).astimezone()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
ValueError: year must be in 1..9999, not 10000
>>> datetime.datetime(9999, 12, 31, tzinfo=datetime.UTC).astimezone()
datetime.datetime(9999, 12, 31, 4, 0, tzinfo=datetime.timezone(datetime.timedelta(seconds=14400), '+04'))
same behavior for _pydatetime module, but I found that in version 3.11 the behavior is as next:
>>> datetime.datetime(9999, 12, 31).astimezone()
datetime.datetime(9999, 12, 31, 0, 0, tzinfo=datetime.timezone(datetime.timedelta(seconds=14400), '+04'))
EDIT: same behavior for datetime(1, 1, 1):
>>> datetime.datetime(1, 1, 1).astimezone()
Traceback (most recent call last):
File "<python-input-23>", line 1, in <module>
datetime.datetime(1, 1, 1).astimezone()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
ValueError: year must be in 1..9999, not 0
CPython versions tested on:
CPython main branch, 3.13, 3.12
Operating systems tested on:
Linux
Linked PRs
- gh-130752
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
datetime.astimezone のエントリポイントから始め、CPython main で報告されている年 1 と年 9999 のケースを再現し、Python 3.11 の挙動と比較します。続行する前に、リンクされている PR gh-130752 を確認してください。境界ケースで予期せずエラーが発生しなくなり、意図した挙動が関連するテストでカバーされたら作業完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 20/100