Add warning

This commit is contained in:
Adam Turner
2022-05-28 19:06:48 +01:00
parent 57e4a2f4cc
commit a3d0983552
2 changed files with 20 additions and 0 deletions

View File

@@ -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 @@ class Config:
# 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 {})

View File

@@ -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."""