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

Do not use datetime.utcnow() that is deprecated in Python 3.12 #972

Merged
merged 5 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jupyter_client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def default_secure(cfg: t.Any) -> None: # pragma: no cover

def utcnow() -> datetime:
"""Return timezone-aware UTC timestamp"""
return datetime.utcnow().replace(tzinfo=utc) # noqa
return datetime.now(utc) # noqa
davidbrochart marked this conversation as resolved.
Show resolved Hide resolved


# -----------------------------------------------------------------------------
Expand Down
35 changes: 2 additions & 33 deletions jupyter_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
- vendor functions from ipython_genutils that should be retired at some point.
"""
import os
from datetime import datetime, timedelta, tzinfo

from jupyter_core.utils import ensure_async, run_sync # noqa: F401 # noqa: F401

from .session import utcnow
davidbrochart marked this conversation as resolved.
Show resolved Hide resolved


def _filefind(filename, path_dirs=None):
"""Find a file by looking through a sequence of paths.
Expand Down Expand Up @@ -84,35 +85,3 @@ def _expand_path(s):
if os.name == "nt":
s = s.replace("IPYTHON_TEMP", "$\\")
return s


# constant for zero offset
ZERO = timedelta(0)


class tzUTC(tzinfo): # noqa
"""tzinfo object for UTC (zero offset)"""

def utcoffset(self, d):
"""Compute utcoffset."""
return ZERO

def dst(self, d):
"""Compute dst."""
return ZERO


UTC = tzUTC() # type:ignore


def utc_aware(unaware):
"""decorator for adding UTC tzinfo to datetime's utcfoo methods"""

def utc_method(*args, **kwargs):
dt = unaware(*args, **kwargs)
return dt.replace(tzinfo=UTC)

return utc_method


utcnow = utc_aware(datetime.utcnow)
Loading