-
-
Notifications
You must be signed in to change notification settings - Fork 29.2k
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
gh-118542: improve datetime deprecation warnings #118571
Open
Max-Herbold
wants to merge
6
commits into
python:main
Choose a base branch
from
Max-Herbold:main
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8549bb7
Update deprecation warnings in utcnow and utcfromtimestamp
Max-Herbold 97c7e5c
📜🤖 Added by blurb_it.
blurb-it[bot] 6454f7f
Update Modules/_datetimemodule.c
Max-Herbold 3c895fe
Update Modules/_datetimemodule.c
Max-Herbold 93888ac
Update deprecation warnings in utcnow and utcfromtimestamp in Doc and…
Max-Herbold 43323ec
add whitespace to end of line
Max-Herbold File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1809,7 +1809,9 @@ def utcfromtimestamp(cls, t): | |
warnings.warn("datetime.datetime.utcfromtimestamp() is deprecated and scheduled " | ||
"for removal in a future version. Use timezone-aware " | ||
"objects to represent datetimes in UTC: " | ||
"datetime.datetime.fromtimestamp(t, datetime.UTC).", | ||
"datetime.datetime.fromtimestamp(t, datetime.UTC). To maintain " | ||
"compatibility datetime.datetime.fromtimestamp(timestamp) " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was observed, if no timezone is provided, |
||
"may be used.", | ||
DeprecationWarning, | ||
stacklevel=2) | ||
return cls._fromtimestamp(t, True, None) | ||
|
@@ -1827,7 +1829,10 @@ def utcnow(cls): | |
warnings.warn("datetime.datetime.utcnow() is deprecated and scheduled for " | ||
"removal in a future version. Use timezone-aware " | ||
"objects to represent datetimes in UTC: " | ||
"datetime.datetime.now(datetime.UTC).", | ||
"datetime.datetime.now(datetime.UTC). To maintain " | ||
"compatibility " | ||
"datetime.datetime.now(datetime.UTC).replace(tzinfo=None) " | ||
"may be used.", | ||
DeprecationWarning, | ||
stacklevel=2) | ||
t = _time.time() | ||
|
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Library/2024-05-04-11-51-06.gh-issue-118542.idPcCx.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Improve datetime utc deprecation warnings. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do decide to offer this approach, I would be much clearer in the message that doing this is effectively equivalent to suppressing the warning without fixing the underlying issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true, this issue was raised (and I had the same experience) because there was no in-place replacement to maintain compatibility provided. I ended up at the same conclusion currently proposed several weeks before the original issue was opened but after some significant time.
Is this the correct understanding here; that the proposed modifications correctly address the case where code written for py<3.12 being run on py>=3.12. But do not adequately address (or propose a misleading solution when) the deprecated functions being called when new code is being written in py>=3.12?