Skip to content

Stop using deprecated datetime.utcnow()#193

Open
c-tonneslan wants to merge 1 commit into
openstates:mainfrom
c-tonneslan:chore/use-utcnow-helper-and-tz-aware-now
Open

Stop using deprecated datetime.utcnow()#193
c-tonneslan wants to merge 1 commit into
openstates:mainfrom
c-tonneslan:chore/use-utcnow-helper-and-tz-aware-now

Conversation

@c-tonneslan

Copy link
Copy Markdown

Python 3.12 deprecated datetime.datetime.utcnow() in favour of datetime.datetime.now(timezone.utc). Swapped the four remaining call sites:

  • openstates/models/common.pyis_active() does .date().isoformat() so no shape change
  • openstates/scrape/tests/test_event_scrape.py, openstates/data/tests/conftest.py, openstates/importers/tests/test_base_importer.py — these compare against / feed naive consumers, so kept the naive UTC shape via .replace(tzinfo=None)

Skipped openstates/cli/update.py and openstates/cli/people.py for now since the values there land in places (GCS object keys, naive DateTimeField saves) where a tz suffix would change behaviour - happy to tackle those in a follow-up if you'd like.

datetime.utcnow() is deprecated in Python 3.12. Swap the remaining
call sites for datetime.now(timezone.utc), keeping the naive-UTC
shape where existing consumers expect it via .replace(tzinfo=None).

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant