Skip to content

Infra: Replace deprecated utcnow and utcfromtimestamp #3148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions generate_rss.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# CC0-1.0-Universal license, whichever is more permissive.

import argparse
import datetime
import datetime as dt
import email.utils
from html import escape
from pathlib import Path
Expand All @@ -19,9 +19,9 @@
PEP_ROOT = Path(__file__).parent


def _format_rfc_2822(dt: datetime.datetime) -> str:
dt = dt.replace(tzinfo=datetime.timezone.utc)
return email.utils.format_datetime(dt, usegmt=True)
def _format_rfc_2822(datetime: dt.datetime) -> str:
datetime = datetime.replace(tzinfo=dt.timezone.utc)
return email.utils.format_datetime(datetime, usegmt=True)


line_cache: dict[Path, dict[str, str]] = {}
Expand Down Expand Up @@ -111,12 +111,12 @@ def first_line_starting_with(full_path: Path, text: str) -> str:
return path_cache.get(text, "")


def pep_creation(full_path: Path) -> datetime.datetime:
def pep_creation(full_path: Path) -> dt.datetime:
created_str = first_line_starting_with(full_path, "Created:")
if full_path.stem == "pep-0102":
# remove additional content on the Created line
created_str = created_str.split(" ", 1)[0]
return datetime.datetime.strptime(created_str, "%d-%b-%Y")
return dt.datetime.strptime(created_str, "%d-%b-%Y")


def parse_rst(full_path: Path) -> nodes.document:
Expand Down Expand Up @@ -150,7 +150,7 @@ def main():

# generate rss items for 10 most recent peps
items = []
for dt, full_path in peps_with_dt[-10:]:
for datetime, full_path in peps_with_dt[-10:]:
try:
pep_num = int(full_path.stem.split("-")[-1])
except ValueError:
Expand All @@ -172,7 +172,7 @@ def main():
<description>{escape(pep_abstract(full_path), quote=False)}</description>
<author>{escape(joined_authors, quote=False)}</author>
<guid isPermaLink="true">{url}</guid>
<pubDate>{_format_rfc_2822(dt)}</pubDate>
<pubDate>{_format_rfc_2822(datetime)}</pubDate>
</item>"""
items.append(item)

Expand All @@ -182,7 +182,7 @@ def main():
language features, and some meta-information like release
procedure and schedules.
"""
last_build_date = _format_rfc_2822(datetime.datetime.utcnow())
last_build_date = _format_rfc_2822(dt.datetime.now(dt.timezone.utc))
items = "\n".join(reversed(items))
output = f"""\
<?xml version='1.0' encoding='UTF-8'?>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import datetime
import datetime as dt
from pathlib import Path
import subprocess

Expand Down Expand Up @@ -66,7 +66,8 @@ def _add_commit_history_info(pep_source_path: Path) -> nodes.paragraph:
except KeyError:
return nodes.paragraph()

iso_time = datetime.datetime.utcfromtimestamp(since_epoch).isoformat(sep=" ")
epoch_dt = dt.datetime.fromtimestamp(since_epoch, dt.timezone.utc)
iso_time = epoch_dt.isoformat(sep=" ")
commit_link = f"https://github.com/python/peps/commits/main/{pep_source_path.name}"
link_node = nodes.reference("", f"{iso_time} GMT", refuri=commit_link)
return nodes.paragraph("", "Last modified: ", link_node)
Expand Down
4 changes: 2 additions & 2 deletions pep_sphinx_extensions/pep_zero_generator/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

import datetime
import datetime as dt
from typing import TYPE_CHECKING
import unicodedata

Expand Down Expand Up @@ -32,7 +32,7 @@
HEADER = f"""\
PEP: 0
Title: Index of Python Enhancement Proposals (PEPs)
Last-Modified: {datetime.date.today()}
Last-Modified: {dt.date.today()}
Author: python-dev <[email protected]>
Status: Active
Type: Informational
Expand Down