GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add `datetime.UTC` alias for `datetime.timezone.utc` · Issue #91928 · python/cpython

Add datetime.UTC alias for datetime.timezone.utc #91928

New issue
Copy link
New issue
Copy link
Closed
#92567
#91973
Closed
Add datetime.UTC alias for datetime.timezone.utc#91928
#92567
#91973
Copy link
Labels
type-featureA feature request or enhancementA feature request or enhancement

Description

@pganssle
pganssle
opened on Apr 25, 2022
Issue body actions

Feature or enhancement

Right now, the UTC singleton is only available as a class-level attribute on datetime.timezone, but I think a lot of people would probably like to be able to do this:

from datetime import UTC

Since datetime.timezone is a class, not a module, right now it is necessary for each person to define their own UTC alias (if they want such a thing) in two lines:

from datetime import timezone
UTC = timezone.utc

This isn't a huge deal, but I think it would be pretty unambiguous what it refers to and might be a nice quality of life improvement.

CC: @abalkin

Reacted by Victor Stinner, Kabir Kwatra, ajoino, Brett Cannon and Oleg Lavrovsky

Activity

  1. pganssle
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Apr 25, 2022
  2. pganssle commented on Apr 27, 2022

    @pganssle
    pganssle
    on Apr 27, 2022
    MemberAuthor
    More actions

    I tracked down the decision between datetime.timezone.utc and datetime.UTC to this conversation primarily between @abalkin and @brettcannon. It was definitely a deliberate decision to use timezone.utc, but it doesn't seem like there were especially strong feelings about this.

    One counter-example to the "datetime seems to put its attributes in class namespaces" is that MINYEAR and MAXYEAR are global module-level constants. I am mostly convinced that we should go forward with this, particularly since a contributor has already written an excellent PR (#91973) implementing it. Any objections from @brettcannon or @abalkin?

    Reacted by ajoino and Kabir Kwatra
  3. brettcannon commented on Apr 28, 2022

    @brettcannon
    brettcannon
    on Apr 28, 2022
    Member
    More actions

    Definitely no objections from me. 🙂

    Reacted by Paul Ganssle, Kabir Kwatra and Collins Oden
  4. pganssle
    added a commit that references this issue on May 3, 2022

    feat(datetime): Add `datetime.UTC` alias for `datetime.timezone.utc`

    This issue will close once commit 65fbe0d is merged into the 'main' branch.
    65fbe0d
  5. miss-islington
    closed this as completedin #91973on May 3, 2022
  6. miss-islington
    added a commit that references this issue on May 3, 2022

    gh-91928: Add `datetime.UTC` alias for `datetime.timezone.utc` (GH-91973

    48c6165
  7. pganssle
    reopened this on May 3, 2022
  8. pganssle commented on May 3, 2022

    @pganssle
    pganssle
    on May 3, 2022
    MemberAuthor
    More actions

    Re-opening because this needs a What's new entry, but I selfishly didn't want to induce a merge conflict with #92177, so I'll add a What's New entry after that one gets merged.

    Reacted by Kabir Kwatra
  9. miss-islington
    closed this as completedin #92567on May 10, 2022
  10. miss-islington
    added 3 commits that reference this issue on May 10, 2022

    gh-91928: Add what's new entry for datetime.UTC alias (GH-92567)

    a0a825c

    pythongh-91928: Add what's new entry for datetime.UTC alias (pythonGH…

    78f1746

    gh-91928: Add what's new entry for datetime.UTC alias (GH-92567)

    2d38a2f
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

    type-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.