summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Turner <9087854+AA-Turner@users.noreply.github.com>2023-04-27 01:30:40 +0100
committerGitHub <noreply@github.com>2023-04-27 01:30:40 +0100
commit3c4e78e2361b1e155fe7f6d29f1112c036d8e3b2 (patch)
tree84aaa7a5374e8739f9e192255038d1e2913ce97f
parentce5ce1ac2d3abd47be494a48edf5320c98f4f3ee (diff)
downloadsphinx-git-3c4e78e2361b1e155fe7f6d29f1112c036d8e3b2.tar.gz
Make ``locale`` required in ``sphinx.util.i18n.format_date()`` (#11366)
-rw-r--r--CHANGES2
-rw-r--r--sphinx/util/i18n.py14
-rw-r--r--tests/test_util_i18n.py6
3 files changed, 3 insertions, 19 deletions
diff --git a/CHANGES b/CHANGES
index fcbbdb432..9d3edcb89 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 3069b5458..268633200 100644
--- a/sphinx/util/i18n.py
+++ b/sphinx/util/i18n.py
@@ -4,7 +4,6 @@ from __future__ import annotations
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 @@ import babel.dates
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 @@ date_format_re = re.compile('(%s)' % '|'.join(date_format_mappings))
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 7be6f3e77..8aae94028 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'