Skip to content

Commit

Permalink
Add warning
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed May 28, 2022
1 parent 57e4a2f commit a3d0983
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sphinx/config.py
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {})

Expand Down
16 changes: 16 additions & 0 deletions tests/test_config.py
Expand Up @@ -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."""

Expand Down

0 comments on commit a3d0983

Please sign in to comment.