From 2fbb5ededc25717e73dba54725ad624a622e6aa2 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Mon, 24 Apr 2023 08:17:21 +0100 Subject: [PATCH 1/2] format_date() deprecation --- sphinx/util/i18n.py | 14 +------------- tests/test_util_i18n.py | 6 ------ 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/sphinx/util/i18n.py b/sphinx/util/i18n.py index 3069b5458f9..268633200ad 100644 --- a/sphinx/util/i18n.py +++ b/sphinx/util/i18n.py @@ -4,7 +4,6 @@ import os import re -import warnings from datetime import datetime, timezone from os import path from typing import TYPE_CHECKING, Callable, Generator, NamedTuple @@ -13,7 +12,6 @@ from babel.messages.mofile import write_mo from babel.messages.pofile import read_po -from sphinx.deprecation import RemovedInSphinx70Warning from sphinx.errors import SphinxError from sphinx.locale import __ from sphinx.util import logging @@ -171,11 +169,6 @@ def docname_to_domain(docname: str, compaction: bool | str) -> str: def babel_format_date(date: datetime, format: str, locale: str, formatter: Callable = babel.dates.format_date) -> str: - if locale is None: - warnings.warn('The locale argument for babel_format_date() becomes required.', - RemovedInSphinx70Warning) - locale = 'en' - # Check if we have the tzinfo attribute. If not we cannot do any time # related formats. if not hasattr(date, 'tzinfo'): @@ -193,7 +186,7 @@ def babel_format_date(date: datetime, format: str, locale: str, def format_date( - format: str, date: datetime | None = None, language: str | None = None, + format: str, *, date: datetime | None = None, language: str, ) -> str: if date is None: # If time is not specified, try to use $SOURCE_DATE_EPOCH variable @@ -204,11 +197,6 @@ def format_date( else: date = datetime.now(timezone.utc).astimezone() - if language is None: - warnings.warn('The language argument for format_date() becomes required.', - RemovedInSphinx70Warning) - language = 'en' - result = [] tokens = date_format_re.split(format) for token in tokens: diff --git a/tests/test_util_i18n.py b/tests/test_util_i18n.py index 7be6f3e779a..8aae9402847 100644 --- a/tests/test_util_i18n.py +++ b/tests/test_util_i18n.py @@ -2,7 +2,6 @@ import datetime import os -import warnings import babel import pytest @@ -57,11 +56,6 @@ def test_format_date(): # strftime format format = '%B %d, %Y' - with warnings.catch_warnings(): - # Test format_date() with no language argument -- this form will be - # removed in Sphinx 7 (xref RemovedInSphinx70Warning) - warnings.simplefilter("ignore") - assert i18n.format_date(format, date=date) == 'February 07, 2016' assert i18n.format_date(format, date=date, language='') == 'February 07, 2016' assert i18n.format_date(format, date=date, language='unknown') == 'February 07, 2016' assert i18n.format_date(format, date=date, language='en') == 'February 07, 2016' From a9871b2de4c6c82bcb99f6bf5f3ee0a0687b3e09 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Thu, 27 Apr 2023 00:41:29 +0100 Subject: [PATCH 2/2] CHANGES --- CHANGES | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES b/CHANGES index 359c02d64c9..579320bb8e6 100644 --- a/CHANGES +++ b/CHANGES @@ -7,6 +7,9 @@ Dependencies Incompatible changes -------------------- +* #11366: Make ``locale`` a required argument to + ``sphinx.util.i18n.format_date()``. + Deprecated ----------