Skip to content

gh-91928: Add datetime.UTC alias for datetime.timezone.utc - #91973

Merged
miss-islington merged 8 commits into
python:mainfrom
Kab1r:feat-datetime-utc-alias
May 3, 2022
Merged

gh-91928: Add datetime.UTC alias for datetime.timezone.utc#91973
miss-islington merged 8 commits into
python:mainfrom
Kab1r:feat-datetime-utc-alias

Conversation

@Kab1r

@Kab1rKab1r commented Apr 27, 2022

Copy link
Copy Markdown
Contributor

fixes#91928

UTC is now module attribute aliased to datetime.timezone.utc.
You can now do the following:

fromdatetimeimportUTC

Automerge-Triggered-By: GH:pganssle

@ghost

ghost commented Apr 27, 2022

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-bot

Copy link
Copy Markdown

Every change to Python requires a NEWS entry.

Please, add it using the blurb_it Web app or the blurb command-line tool.

@pgansslepganssle left a comment

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 looks great, thanks!

In addition to my other comments, two other things:

  1. As I believe you are a first-time contributor, you should probably add your name to Misc/ACKS.
  2. Maybe add a very simple test to TestModule, like this:
deftest_utc_alias(self):
self.assertIs(UTC, timezone.utc)

Thanks for your contribution!

Comment threadMisc/NEWS.d/next/Library/2022-04-26-18-02-44.gh-issue-91928.V0YveU.rst Outdated
Comment threadDoc/library/datetime.rst Outdated
Comment threadDoc/library/datetime.rst Outdated
@bedevere-bot

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@Kab1r

Copy link
Copy Markdown
ContributorAuthor

I have made the requested changes; please review again

@bedevere-bot

Copy link
Copy Markdown

Thanks for making the requested changes!

@pganssle: please review the changes made to this pull request.

@pgansslepganssle left a comment

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 add this test?

Maybe add a very simple test to TestModule, like this:

deftest_utc_alias(self):
self.assertIs(UTC, timezone.utc)

Comment threadDoc/library/datetime.rst Outdated
@bedevere-bot

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@Kab1r

Copy link
Copy Markdown
ContributorAuthor

I had to move the definition of datetime.UTC to the end so that modifications to datetime.timezone.utc doesn't make it a different object.

@Kab1r

Copy link
Copy Markdown
ContributorAuthor

I have made the requested changes; please review again

@bedevere-bot

Copy link
Copy Markdown

Thanks for making the requested changes!

@pganssle: please review the changes made to this pull request.

Kab1rand others added 4 commits May 3, 2022 14:02
1. Add UTC definition into C implementation as well (just for
consistency, there's no particular reason not to simply assign the
alias in the Python code later).
2. Move `..versionadded` tag into the right place
@pganssle
pganssleforce-pushed the feat-datetime-utc-alias branch from c097669 to 9542f54CompareMay 3, 2022 20:02
@pganssle

Copy link
Copy Markdown
Member

Thanks @Kab1r!

natoscott added a commit to natoscott/pcp that referenced this pull request May 8, 2025
Resolves an issue Ken reported running tests in the QA farm,
which is due to use of an interface from more-recent-python:
python/cpython#91973
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add datetime.UTC alias for datetime.timezone.utc

4 participants

@Kab1r@bedevere-bot@pganssle@miss-islington