Skip to content

Commit 60c1095

Browse files
ellertpre-commit-ci[bot]davidbrochartblink1073
authored
Do not use datetime.utcnow() that is deprecated in Python 3.12 (#972)
* Do not use datetime.utcnow() that is deprecated in Python 3.12 Import session.utcnow() into utils instead of reimplementing it * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove unneeded noqa * Add noqa --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: David Brochart <[email protected]> Co-authored-by: Steven Silvester <[email protected]>
1 parent fe93a44 commit 60c1095

File tree

2 files changed

+3
-34
lines changed

2 files changed

+3
-34
lines changed

jupyter_client/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def default_secure(cfg: t.Any) -> None: # pragma: no cover
197197

198198
def utcnow() -> datetime:
199199
"""Return timezone-aware UTC timestamp"""
200-
return datetime.utcnow().replace(tzinfo=utc) # noqa
200+
return datetime.now(utc)
201201

202202

203203
# -----------------------------------------------------------------------------

jupyter_client/utils.py

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
- vendor functions from ipython_genutils that should be retired at some point.
55
"""
66
import os
7-
from datetime import datetime, timedelta, tzinfo
87

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

10+
from .session import utcnow # noqa
11+
1112

1213
def _filefind(filename, path_dirs=None):
1314
"""Find a file by looking through a sequence of paths.
@@ -84,35 +85,3 @@ def _expand_path(s):
8485
if os.name == "nt":
8586
s = s.replace("IPYTHON_TEMP", "$\\")
8687
return s
87-
88-
89-
# constant for zero offset
90-
ZERO = timedelta(0)
91-
92-
93-
class tzUTC(tzinfo): # noqa
94-
"""tzinfo object for UTC (zero offset)"""
95-
96-
def utcoffset(self, d):
97-
"""Compute utcoffset."""
98-
return ZERO
99-
100-
def dst(self, d):
101-
"""Compute dst."""
102-
return ZERO
103-
104-
105-
UTC = tzUTC() # type:ignore[abstract]
106-
107-
108-
def utc_aware(unaware):
109-
"""decorator for adding UTC tzinfo to datetime's utcfoo methods"""
110-
111-
def utc_method(*args, **kwargs):
112-
dt = unaware(*args, **kwargs)
113-
return dt.replace(tzinfo=UTC)
114-
115-
return utc_method
116-
117-
118-
utcnow = utc_aware(datetime.utcnow)

0 commit comments

Comments
 (0)