Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pganssle opened this issue Apr 25, 2022 · 3 comments · Fixed by #91973 or #92567
Closed

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

pganssle opened this issue Apr 25, 2022 · 3 comments · Fixed by #91973 or #92567
Labels
type-feature A feature request or enhancement

Comments

@pganssle
Copy link
Member

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

@pganssle
Copy link
Member Author

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?

@brettcannon
Copy link
Member

Definitely no objections from me. 🙂

pganssle pushed a commit to Kab1r/cpython that referenced this issue May 3, 2022
miss-islington pushed a commit that referenced this issue May 3, 2022
)

### fixes #91928

`UTC` is now module attribute aliased to `datetime.timezone.utc`.
You can now do the following:
```python
from datetime import UTC
```
@pganssle pganssle reopened this May 3, 2022
@pganssle
Copy link
Member Author

pganssle commented 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.

miss-islington pushed a commit that referenced this issue May 10, 2022
I merged this without a What's New entry to avoid merge conflicts, so here's the follow-up adding the entry.

@Kab1r do you mind reviewing?

Closes #91928

Automerge-Triggered-By: GH:pganssle
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 10, 2022
…-92567)

I merged this without a What's New entry to avoid merge conflicts, so here's the follow-up adding the entry.

@Kab1r do you mind reviewing?

Closes pythonGH-91928

Automerge-Triggered-By: GH:pganssle
(cherry picked from commit a0a825c)

Co-authored-by: Paul Ganssle <1377457+pganssle@users.noreply.github.com>
miss-islington added a commit that referenced this issue May 10, 2022
I merged this without a What's New entry to avoid merge conflicts, so here's the follow-up adding the entry.

@Kab1r do you mind reviewing?

Closes GH-91928

Automerge-Triggered-By: GH:pganssle
(cherry picked from commit a0a825c)

Co-authored-by: Paul Ganssle <1377457+pganssle@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
2 participants