`utcnow` deprecation note is misleading
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Documentation
Currently, the deprecation notice for datetime.utcnow() reads:
Deprecated since version 3.12: Use
datetime.now()withUTCinstead.
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, usedatetime.now(UTC).replace(tzinfo=None).
Maybe someone can come up with a better wording.
Linked PRs
- gh-118571
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the datetime.datetime.utcnow() documentation at the linked datetime page and compare the proposed wording with PR gh-118571. Done means the deprecation note clearly warns that datetime.now(UTC) returns an aware datetime and states the replace(tzinfo=None) compatibility option, or adopts an agreed better wording.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100