Skip to content

gh-160035: Simplify datetime awareness docs - #160086

Open
Milan-CSE wants to merge 1 commit into
python:mainfrom
Milan-CSE:gh-160035-simplify-tz-awareness-docs
Open

Milan-CSE wants to merge 1 commit into
python:mainfrom
Milan-CSE:gh-160035-simplify-tz-awareness-docs

Conversation

@Milan-CSE

Copy link
Copy Markdown

Summary

Simplifies the documentation for determining whether datetime and time objects are aware or naive.

Both objects' utcoffset() methods already account for the presence of timezone information and whether the resulting UTC offset is None. The updated wording explains this more directly.

Issue

gh-160035

Verification

  • Doc/make.bat check — passed.
  • python -m test test_datetime — passed (1,098 tests run, 106 skipped).
  • Documentation parsing — passed without reported warnings or markup errors.

@python-cla-bot

python-cla-bot Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-project-automation github-project-automation Bot moved this to Todo in Docs PRs Oct 21, 2026
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35306084 | 📁 Comparing af7e82d against main (796b26b)

  🔍 Preview build  

25 files changed · + 1 added · ± 24 modified

+ Added

± Modified

Comment thread Doc/library/datetime.rst
An object of type :class:`.time` or :class:`.datetime` may be aware or naive.

A :class:`.datetime` object ``d`` is aware if both of the following hold:
A :class:`.datetime` object ``d`` is aware if ``d.utcoffset()`` does not return

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add references to the methods, you can put the proper target in <...> to keep the text as is.

I think this an improvement, the majority of readers likely care more about the practical test than underlying details. Any thoughts @pganssle ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole thing is actually a very odd definition if you think about it. In practice, for datetime, none of the major tzinfo implementations will return None for any datetime. Even if it did sometimes return None, that would be a very odd definition of naïve.

I think the reason for this is time objects, which get the same tzinfo objects attached to them, but when those have any transitions they are returning None, but it's also very odd to consider those times naïve just because you don't know what the offset is.

But I suppose that logically it does make sense to document it this way. (Though in practice it's probably much faster to check .tzinfo is None, so dt.tzinfo is None or dt.utcoffset() is None is more performant, though if that is someone's bottleneck I'm sure they will figure it out).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting merge docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

4 participants