diff --git a/sphinx/config.py b/sphinx/config.py index 9e05bc1b3dc..27653f307a4 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -3,6 +3,7 @@ import re import traceback import types +import warnings from collections import OrderedDict from os import getenv, path from typing import (TYPE_CHECKING, Any, Callable, Dict, Generator, Iterator, List, NamedTuple, @@ -168,6 +169,9 @@ def read(cls, confdir: str, overrides: Dict = None, tags: Tags = None) -> "Confi # explicitly sets language to None, by coercing it to English. if namespace.get("language", ...) is None: namespace["language"] = "en" + warnings.warn("'None' is not a valid value for 'language', coercing to 'en'. " + "Update 'conf.py' to a valid language code to silence this " + "warning.", RuntimeWarning, stacklevel=4) return cls(namespace, overrides or {}) diff --git a/tests/test_config.py b/tests/test_config.py index 804772d4675..8d707ae252b 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -397,6 +397,22 @@ def test_conf_py_language_none(tempdir): assert cfg.language == "en" +def test_conf_py_language_none_warning(tempdir): + """Regression test for #10474.""" + + # Given a conf.py file with language = None + (tempdir / 'conf.py').write_text("language = None", encoding='utf-8') + + # Then a warning is raised + with pytest.warns( + RuntimeWarning, + match="'None' is not a valid value for 'language', coercing to 'en'. " + "Update 'conf.py' to a valid language code to silence this " + "warning."): + # When we load conf.py into a Config object + Config.read(tempdir, {}, None) + + def test_conf_py_no_language(tempdir): """Regression test for #10474."""