refactor: Upgrade code for Python 3.11 and above

This commit is contained in:
Justin Mayer 2026-03-31 08:56:27 +02:00
commit 74feb7c48b
5 changed files with 13 additions and 19 deletions

View file

@ -2,12 +2,7 @@ import datetime
import os
import sys
import time
if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib
import tomllib
sys.path.append(os.path.abspath(os.pardir))
@ -32,7 +27,7 @@ source_suffix = ".rst"
master_doc = "index"
project = project_data.get("name").upper()
year = datetime.datetime.fromtimestamp(
int(os.environ.get("SOURCE_DATE_EPOCH", time.time())), datetime.timezone.utc
int(os.environ.get("SOURCE_DATE_EPOCH", time.time())), datetime.UTC
).year
project_copyright = f"2010{year}" # noqa: RUF001
exclude_patterns = ["_build"]

View file

@ -590,7 +590,7 @@ class Article(Content):
if self.date.tzinfo is None:
now = datetime.datetime.now()
else:
now = datetime.datetime.now(datetime.timezone.utc)
now = datetime.datetime.now(datetime.UTC)
if self.date > now:
self.status = "draft"

View file

@ -2,7 +2,7 @@ import locale
import logging
import os
import shutil
from datetime import timezone
from datetime import UTC
from sys import platform
from tempfile import mkdtemp
@ -62,7 +62,7 @@ class TestUtils(LoggedTestCase):
date = utils.SafeDatetime(year=2012, month=11, day=22)
date_hour = utils.SafeDatetime(year=2012, month=11, day=22, hour=22, minute=11)
date_hour_z = utils.SafeDatetime(
year=2012, month=11, day=22, hour=22, minute=11, tzinfo=timezone.utc
year=2012, month=11, day=22, hour=22, minute=11, tzinfo=UTC
)
date_hour_wib = utils.SafeDatetime(
year=2012,
@ -82,7 +82,7 @@ class TestUtils(LoggedTestCase):
hour=22,
minute=11,
second=10,
tzinfo=timezone.utc,
tzinfo=UTC,
)
date_hour_sec_wib = utils.SafeDatetime(
year=2012,
@ -101,7 +101,7 @@ class TestUtils(LoggedTestCase):
minute=11,
second=10,
microsecond=123000,
tzinfo=timezone.utc,
tzinfo=UTC,
)
dates = {
"2012-11-22": date,

View file

@ -446,13 +446,13 @@ def tumblr2fields(api_key, blogname):
slug = post.get("slug") or slugify(title, regex_subs=subs)
tags = post.get("tags")
timestamp = post.get("timestamp")
date = SafeDatetime.fromtimestamp(
int(timestamp), tz=datetime.timezone.utc
).strftime("%Y-%m-%d %H:%M:%S%z")
date = SafeDatetime.fromtimestamp(int(timestamp), tz=datetime.UTC).strftime(
"%Y-%m-%d %H:%M:%S%z"
)
slug = (
SafeDatetime.fromtimestamp(
int(timestamp), tz=datetime.timezone.utc
).strftime("%Y-%m-%d-")
SafeDatetime.fromtimestamp(int(timestamp), tz=datetime.UTC).strftime(
"%Y-%m-%d-"
)
+ slug
)
post_format = post.get("format")

View file

@ -3,4 +3,3 @@ sphinxext-opengraph
furo==2023.9.10
livereload
matplotlib
tomli;python_version<"3.11"