Fix py3.12 warnings for datetime usage, non-raw regex strings #632
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.
After upgrading my
python3
frompython-3.9
topython-3.12
, running thetest
target causes a bunch of new warnings to be emitted. These are regardingdatetime.datetime.utcnow()
being deprecated. This is because upstream wants to make changes to naive datetimes (those withouttzdata
).Here is the blurb from https://docs.python.org/3/whatsnew/3.12.html:
There is some discussion of upstream's rationale in python/cpython#81669.
For the fix, I chose to use
datetime.timezone.utc
rather thandatetime.UTC
because the latter was only added inpython-3.11
and I wanted the tests to work under bothpython-3.9
andpython-3.12
.The following edit sequences were run to produce the changes:
First,
test_totals.t
had imported all ofdatetime
, unlike all the other files which were importing individual namesfrom datetime
. It also did a wildcard import fromext/totals.py
which caused a shadowing issue so I made the imports more specific. Now taht file importsdatetime
like the others, so later mass-edits (below) will work on this file too:Next, we replace the deprecated
utcnow()
with a tzinfo-aware call, which can be done directly by giving a zone argument tonow()
but in other uses, a tzinfo-naive object is obtained, used for some things, and then later its.utcnow()
method is run. We had to convert those uses in-place by first localizing:Finally, I removed the
tzlocal
import from files that didn't need it because they didn't do a conversion from naive objects to a aware objects (in the transform above):Incidentally, there were some regexes in
summary.t
that are not raw-quoted, generating a warning on embedded\d
in non-raw quoted strings. These were probably already warnings before. They were fixed en passant in a separate commit.Please apply, thanks.