diff --git a/CHANGES b/CHANGES index fcbbdb43295..9d3edcb8969 100644 --- a/CHANGES +++ b/CHANGES @@ -15,6 +15,8 @@ Incompatible changes ``setup.py``). * #11364: Remove deprecated ``sphinx.ext.napoleon.iterators`` module. * #11365: Remove support for the ``jsdump`` format in ``sphinx.search``. +* #11366: Make ``locale`` a required argument to + ``sphinx.util.i18n.format_date()``. Deprecated ---------- 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'