You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add datetime.UTC alias for datetime.timezone.utc #91928
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:
fromdatetimeimportUTC
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:
fromdatetimeimporttimezoneUTC=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.
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?
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.
Activity
pganssle commentedon Apr 27, 2022
I tracked down the decision between
datetime.timezone.utcanddatetime.UTCto this conversation primarily between @abalkin and @brettcannon. It was definitely a deliberate decision to usetimezone.utc, but it doesn't seem like there were especially strong feelings about this.One counter-example to the "
datetimeseems to put its attributes in class namespaces" is thatMINYEARandMAXYEARare 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?brettcannon commentedon Apr 28, 2022
Definitely no objections from me. 🙂
feat(datetime): Add `datetime.UTC` alias for `datetime.timezone.utc`
gh-91928: Add `datetime.UTC` alias for `datetime.timezone.utc` (GH-91973
pganssle commentedon May 3, 2022
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.
gh-91928: Add what's new entry for datetime.UTC alias (GH-92567)
pythongh-91928: Add what's new entry for datetime.UTC alias (pythonGH…
gh-91928: Add what's new entry for datetime.UTC alias (GH-92567)