◐ Shell
reader mode source ↗
Skip to content

bpo-37488 : Document a warning for datetime.utcnow() and utcfromtimestamp()#15773

Merged
miss-islington merged 1 commit into
python:masterfrom
nanjekyejoannah:issue37488
Sep 11, 2019
Merged

bpo-37488 : Document a warning for datetime.utcnow() and utcfromtimestamp()#15773
miss-islington merged 1 commit into
python:masterfrom
nanjekyejoannah:issue37488

Conversation

@nanjekyejoannah

@nanjekyejoannah nanjekyejoannah commented Sep 9, 2019

Copy link
Copy Markdown
Contributor

@pganssle

pganssle commented Sep 9, 2019

Copy link
Copy Markdown
Member

@nanjekyejoannah I don't think we can (or possibly should) put an actual warning in the code here - people will likely complain about it and we're not actually deprecating the function yet, it will likely just cause a lot of uproar and spam (as much as I'd like to...).

What I was referring to in bpo-15733 was a warning box in the documentation, like:

.. warning::

    Because naive datetimes are treated by many functions as local times,
    it is recommended that you create a timezone-aware datetime using
    ``datetime.now(tz=timezone.utc)`` instead.

I have not spent much time thinking about this. We may want a little footnote showing one of the gotchas to be referenced by both utcfromtimestamp and utcnow.

@nanjekyejoannah

nanjekyejoannah commented Sep 9, 2019

Copy link
Copy Markdown
Contributor Author

Okay. I had thought you wanted us to introduce a warning. I will update this PR accordingly.

@nanjekyejoannah nanjekyejoannah changed the title bpo-37488 : Add warning to datetime.utcnow() and datetime.utcfromtimestamp() Sep 9, 2019
@nanjekyejoannah nanjekyejoannah changed the title bpo-37488 : Document a warning for datetime.utcnow() Sep 9, 2019
@aeros aeros added the docs Documentation in the Doc dir label Sep 10, 2019

@aeros aeros left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hide comment

Thanks for the PR @nanjekyejoannah.

I have a few suggestions:

@pganssle

Copy link
Copy Markdown
Member

@nanjekyejoannah I believe this will have merge conflicts now that #13410 has been merged. Can you rebase against master? I also think adding a warning in utctimetuple() will allow us to close #10870.

@aeros aeros left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hide comment

@nanjekyejoannah For consistency, can provide the warning message for each of them?

Because naive datetime objects are treated by many datetime methods
as local times, the recommended way to create aware datetime objects for
the current time in UTC is by calling datetime.now(timezone.utc).

Otherwise, everything else looks good to me.

This also removes several examples using utc* methods, to avoid
confusion.

bpo-37488: https://bugs.python.org/issue37488
@miss-islington

Copy link
Copy Markdown
Contributor

@nanjekyejoannah: Status check is done, and it's a success ✅ .

@miss-islington miss-islington merged commit 1a53c78 into python:master Sep 11, 2019
@nanjekyejoannah nanjekyejoannah deleted the issue37488 branch September 11, 2019 14:33
DinoV pushed a commit to DinoV/cpython that referenced this pull request Sep 12, 2019
@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @nanjekyejoannah for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 12, 2019
…tamp() (pythonGH-15773)

https://bugs.python.org/issue37488

Automerge-Triggered-By: @pganssle
(cherry picked from commit 1a53c78)

Co-authored-by: Joannah Nanjekye <33177550+nanjekyejoannah@users.noreply.github.com>
@bedevere-bot

Copy link
Copy Markdown

GH-16059 is a backport of this pull request to the 3.8 branch.

miss-islington added a commit that referenced this pull request Sep 12, 2019
…tamp() (GH-15773)

https://bugs.python.org/issue37488

Automerge-Triggered-By: @pganssle
(cherry picked from commit 1a53c78)

Co-authored-by: Joannah Nanjekye <33177550+nanjekyejoannah@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants