python / python/cpython

`utcnow` deprecation note is misleading

未關閉
#118,542 5 則留言 2 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

3.12 3.13 docs
主要語言
Python
星號
77.2k
分支
36k
PR 合併指標
PR 指標待擷取

描述

Documentation

Currently, the deprecation notice for datetime.utcnow() reads:

Deprecated since version 3.12: Use datetime.now() with UTC instead.

Unfortunately, applying this suggestion verbatim can easily break user code – especially when applying it to libraries. (See for example https://foss.heptapod.net/openpyxl/openpyxl/-/issues/2051). These datetime-related TypeErrors are easy to introduce, and fairly hard to fix. I suggest to amend the deprecation notice:

Deprecated since version 3.12: Use datetime.now(UTC) instead. Please note that this will return an aware datetime object. If you need to remain compatible, use datetime.now(UTC).replace(tzinfo=None).

Maybe someone can come up with a better wording.

Linked PRs
  • gh-118571

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

查看連結的 datetime 頁面中關於 datetime.datetime.utcnow() 的文件,並將提議的措辭與 PR gh-118571 進行比較。當 deprecation note 明確警告 datetime.now(UTC) 會回傳一個 aware datetime,並說明相容性選項 replace(tzinfo=None),或採用已達成共識的更佳措辭時,即視為完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
documentation
Issue 類型
文件
難度
2/5
預估耗時
1-3 小時
活躍度
停滯
描述清晰度
描述清楚
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。