{{ message }}
gh-103857: Update deprecation stacktrace to point to calling line#104431
Merged
abalkin merged 2 commits intoMay 12, 2023
Merged
gh-103857: Update deprecation stacktrace to point to calling line#104431abalkin merged 2 commits into
abalkin merged 2 commits into
Conversation
Member
|
I think |
Sorry, something went wrong.
abalkin
approved these changes
May 12, 2023
abalkin
left a comment
Member
There was a problem hiding this comment.
Looks right.
Sorry, something went wrong.
Member
The stacklevel setting in the pure python implementation is actually correct because warning is generated inside a python,rather than a C function in this case: def utcfromtimestamp(cls, t):
"""Construct a naive UTC datetime from a POSIX timestamp."""
import warnings
warnings.warn("datetime.utcfromtimestamp() is deprecated and scheduled "
"for removal in a future version. Use timezone-aware "
"objects to represent datetimes in UTC: "
"datetime.fromtimestamp(t, datetime.UTC).",
DeprecationWarning,
stacklevel=2)
return cls._fromtimestamp(t, True, None)To test, create the following file: cat > test_103857.py
import sys
sys.modules['_datetime'] = None
from datetime import datetime
def f():
return datetime.utcfromtimestamp(0)
f()and run % ./python.exe -W always test_103857.py
/Users/a/Work/abalkin/cpython-1/test_103857.py:6: DeprecationWarning: datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.fromtimestamp(t, datetime.UTC).
return datetime.utcfromtimestamp(0) |
Sorry, something went wrong.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.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.
Set up
Before
Warnings don't point to the actual lines of code that calls the deprecated
utcfromtimestampandutcnow:After
Now points to the actual lines of code directly calling
utcfromtimestampandutcnow:utcnowandutcfromtimestamp#103857