Skip to content

Datetime docs on determining tz-awareness can be simplified with utcoffset method #160035

Closed

Description

@takluyver

Documentation

The docs on Determining if a [datetime] object is aware or naive direct you to check if d.tzinfo is None, and if not, whether d.tzinfo.utcoffset() returns None.

It appears that this can be simplfied to a single check of d.utcoffset() is None (and likewise for time objects) since the docs for the datetime.utcoffset() method say it incorporates both steps:

If tzinfo is None, returns None, else returns self.tzinfo.utcoffset(self) ...

This method does also do some extra checks ("raises an exception if the latter doesn’t return None or a timedelta object with magnitude less than one day"), but that appears to be only to catch badly implemented tzinfo objects, so it doesn't seem like a reason not to use it.

Linked PRs

Activity

  1. Milan-CSE commented on Oct 21, 2026

    @Milan-CSE
    Contributor

    I'd like to work on this documentation improvement. I'll check the existing datetime documentation and propose a minimal change using d.utcoffset() is None, while preserving the explanation of timezone-aware and naive objects. Please let me know if someone is already working on it.

  2. added 3 commits that reference this issue on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions