Skip to content
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

format_date() deprecation #11366

Merged
merged 3 commits into from Apr 27, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -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
----------
Expand Down
14 changes: 1 addition & 13 deletions sphinx/util/i18n.py
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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'):
Expand All @@ -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
Expand All @@ -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:
Expand Down
6 changes: 0 additions & 6 deletions tests/test_util_i18n.py
Expand Up @@ -2,7 +2,6 @@

import datetime
import os
import warnings

import babel
import pytest
Expand Down Expand Up @@ -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'
Expand Down