GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-103857: Update deprecation stacktrace to point to calling line by hugovk · Pull Request #104431 · python/cpython

Conversation

@hugovk

@hugovk hugovk commented May 12, 2023 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Set up

# From CPython repo:
git clone https://github.com/hugovk/pepotron ../pepotron
./python.exe -m pip install "../pepotron[tests]"

Before

Warnings don't point to the actual lines of code that calls the deprecated utcfromtimestamp and utcnow:

$ ./python.exe -m pytest ../pepotron
...
==================================================================== warnings summary =====================================================================
../../.local/lib/python3.12/site-packages/dateutil/tz/__init__.py:2
  /Users/hugo/.local/lib/python3.12/site-packages/dateutil/tz/__init__.py:2: DeprecationWarning: datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.now(datetime.UTC).
    from .tz import *

tests/test_pepotron.py::test_url[dead batteries-https://peps.python.org/pep-0594/]
tests/test_pepotron.py::test_url_base_url[dead batteries-https://hugovk.github.io/peps-https://hugovk.github.io/peps/pep-0594/]
  /Users/hugo/.local/lib/python3.12/site-packages/pepotron/__init__.py:54: DeprecationWarning: datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.now(datetime.UTC).
    cache_file = _cache.filename(json_url)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
...

After

Now points to the actual lines of code directly calling utcfromtimestamp and utcnow:

$ $ ./python.exe -m pytest ../pepotron
...
==================================================================== warnings summary =====================================================================
../../.local/lib/python3.12/site-packages/dateutil/tz/tz.py:37
  /Users/hugo/.local/lib/python3.12/site-packages/dateutil/tz/tz.py:37: DeprecationWarning: datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.now(datetime.UTC).
    EPOCH = datetime.datetime.utcfromtimestamp(0)

tests/test_pepotron.py::test_url[dead batteries-https://peps.python.org/pep-0594/]
tests/test_pepotron.py::test_url_base_url[dead batteries-https://hugovk.github.io/peps-https://hugovk.github.io/peps/pep-0594/]
  /Users/hugo/.local/lib/python3.12/site-packages/pepotron/_cache.py:30: DeprecationWarning: datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.now(datetime.UTC).
    today = dt.datetime.utcnow().strftime("%Y-%m-%d")

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
...
  • Issue: Deprecate utcnow and utcfromtimestamp #103857

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@hugovk
Update deprecation stacktrace to point to calling line
4e5f7ca
@hugovk
hugovk requested review from abalkin and pganssle as code owners May 12, 2023 16:27
@bedevere-bot bedevere-bot added the awaiting core review label May 12, 2023
@bedevere-bot bedevere-bot mentioned this pull request May 12, 2023
Deprecate utcnow and utcfromtimestamp #103857
Closed
@hugovk
Add news file
ea8c457
@pganssle

pganssle commented May 12, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

I think _pydatetime.py presumably needs to be updated as well.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

abalkin
abalkin approved these changes May 12, 2023
View reviewed changes

@abalkin abalkin left a comment

Copy link
Copy Markdown
Member

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.

Looks right.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels May 12, 2023
@abalkin
abalkin merged commit 25db95d into python:main May 12, 2023
@bedevere-bot bedevere-bot removed the awaiting merge label May 12, 2023
@abalkin

abalkin commented May 12, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

I think _pydatetime.py presumably needs to be updated as well.

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)
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hugovk
hugovk deleted the datetime-deprecations-stacktrace branch May 13, 2023 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@abalkin abalkin abalkin approved these changes
@pganssle pganssle Awaiting requested review from pganssle pganssle is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@hugovk @pganssle @abalkin @bedevere-bot
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.