Skip to content

Commit 5c5b501

Browse files
authored
Clean up config and address warnings (#1353)
1 parent b882a32 commit 5c5b501

File tree

3 files changed

+12
-28
lines changed

3 files changed

+12
-28
lines changed

jupyter_server/_tz.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
# Distributed under the terms of the Modified BSD License.
88
from __future__ import annotations
99

10-
from datetime import datetime, timedelta, tzinfo
11-
from typing import Callable
10+
from datetime import datetime, timedelta, timezone, tzinfo
1211

1312
# constant for zero offset
1413
ZERO = timedelta(0)
@@ -26,21 +25,16 @@ def dst(self, d: datetime | None) -> timedelta:
2625
return ZERO
2726

2827

29-
UTC = tzUTC() # type:ignore[abstract]
30-
28+
def utcnow() -> datetime:
29+
"""Return timezone-aware UTC timestamp"""
30+
return datetime.now(timezone.utc)
3131

32-
def utc_aware(unaware: Callable[..., datetime]) -> Callable[..., datetime]:
33-
"""decorator for adding UTC tzinfo to datetime's utcfoo methods"""
3432

35-
def utc_method(*args, **kwargs):
36-
dt = unaware(*args, **kwargs)
37-
return dt.replace(tzinfo=UTC)
33+
def utcfromtimestamp(timestamp):
34+
return datetime.fromtimestamp(timestamp, timezone.utc)
3835

39-
return utc_method
4036

41-
42-
utcfromtimestamp = utc_aware(datetime.utcfromtimestamp)
43-
utcnow = utc_aware(datetime.utcnow)
37+
UTC = tzUTC() # type:ignore[abstract]
4438

4539

4640
def isoformat(dt: datetime) -> str:

pyproject.toml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ classifiers = [
2020
"Programming Language :: Python",
2121
"Programming Language :: Python :: 3",
2222
"Programming Language :: Python :: 3 :: Only",
23-
"Programming Language :: Python :: 3.8",
24-
"Programming Language :: Python :: 3.9",
25-
"Programming Language :: Python :: 3.10",
26-
"Programming Language :: Python :: 3.11",
2723
]
2824
requires-python = ">=3.8"
2925
dependencies = [
@@ -249,7 +245,7 @@ minversion = "6.0"
249245
xfail_strict = true
250246
log_cli_level = "info"
251247
addopts = [
252-
"-raXs", "--durations=10", "--color=yes", "--doctest-modules",
248+
"-ra", "--durations=10", "--color=yes", "--doctest-modules",
253249
"--showlocals", "--strict-markers", "--strict-config"
254250
]
255251
testpaths = [
@@ -265,14 +261,8 @@ filterwarnings = [
265261
"always:unclosed <socket.socket:ResourceWarning",
266262
"module:Jupyter is migrating its paths to use standard platformdirs:DeprecationWarning",
267263
"ignore:jupyter_server.base.zmqhandlers module is deprecated in Jupyter Server 2.0:DeprecationWarning",
268-
"ignore:datetime.datetime.utcfromtimestamp:DeprecationWarning",
269-
"ignore:datetime.datetime.utcnow:DeprecationWarning",
270-
# from nbformat
271-
"ignore:Importing ErrorTree directly from the jsonschema package:DeprecationWarning",
272-
# From jupyter_events
273-
"module:jsonschema.RefResolver is deprecated as of:DeprecationWarning",
274-
# ignore pytest warnings.
275-
"ignore:::_pytest",
264+
"ignore:datetime.datetime.utc:DeprecationWarning:dateutil",
265+
"ignore:datetime.datetime.utc:DeprecationWarning:tornado",
276266
]
277267

278268
[tool.coverage.report]
@@ -325,4 +315,4 @@ exclude = ["docs", "test"]
325315
ignore = ["W002"]
326316

327317
[tool.repo-review]
328-
ignore = ["PY007", "PP308", "GH102", "MY101"]
318+
ignore = ["PY007", "GH102"]

tests/test_gateway.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def generate_kernelspec(name):
7878

7979
def generate_model(name):
8080
"""Generate a mocked kernel model. Caller is responsible for adding model to running_kernels dictionary."""
81-
dt = datetime.utcnow().isoformat() + "Z" # noqa
81+
dt = datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
8282
kernel_id = str(uuid.uuid4())
8383
model = {
8484
"id": kernel_id,

0 commit comments

Comments
 (0)