Skip to content

Commit

Permalink
Fix use of the deprecated datetime.utcnow method (#1758)
Browse files Browse the repository at this point in the history
This PR replaces uses of the deprecated (as of Python 3.12)
`datetime.utcnow` method. Note that this isn't quite a like-for-like
change: there's a slight difference in the output format. Given that the
event tracer is barely used in practice, I doubt this change matters
much.

```
>>> from datetime import datetime, timezone
>>> datetime.now(timezone.utc).isoformat(" ")
'2023-09-11 16:31:35.534330+00:00'
>>> datetime.utcnow().isoformat(" ")
'2023-09-11 16:31:56.798474'
```
  • Loading branch information
mdickinson committed Sep 11, 2023
1 parent f644cc2 commit 36a95d5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions traits/util/event_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import os
import threading
from contextlib import contextmanager
from datetime import datetime
from datetime import datetime, timezone

from traits import trait_notifiers

Expand Down Expand Up @@ -228,7 +228,7 @@ def pre_tracer(self, obj, name, old, new, handler):
"""
indent = self.indent
time = datetime.utcnow().isoformat(" ")
time = datetime.now(timezone.utc).isoformat(" ")
container = self.container
container.record(
ChangeMessageRecord(
Expand All @@ -255,7 +255,7 @@ def post_tracer(self, obj, name, old, new, handler, exception=None):
""" Record a string representation of the trait change return
"""
time = datetime.utcnow().isoformat(" ")
time = datetime.now(timezone.utc).isoformat(" ")
self.indent -= 1
indent = self.indent
if exception:
Expand Down

0 comments on commit 36a95d5

Please sign in to comment.