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

Coerce language = None in conf.py to Engligh #10481

Merged
merged 10 commits into from May 29, 2022
6 changes: 6 additions & 0 deletions sphinx/config.py
Expand Up @@ -163,6 +163,12 @@ def read(cls, confdir: str, overrides: Dict = None, tags: Tags = None) -> "Confi
raise ConfigError(__("config directory doesn't contain a conf.py file (%s)") %
confdir)
namespace = eval_config_file(filename, tags)

# Resolve https://github.com/sphinx-doc/sphinx/issues/10474 where conf.py
# explicitly sets language to None, by coercing it to English.
if namespace.get("language", ...) is None:
namespace["language"] = "en"
tk0miya marked this conversation as resolved.
Show resolved Hide resolved

return cls(namespace, overrides or {})

def convert_overrides(self, name: str, value: Any) -> Any:
Expand Down
28 changes: 28 additions & 0 deletions tests/test_config.py
Expand Up @@ -381,3 +381,31 @@ def test_nitpick_ignore_regex_fullmatch(app, status, warning):
assert len(warning) == len(nitpick_warnings)
for actual, expected in zip(warning, nitpick_warnings):
assert expected in actual


def test_conf_py_language_none(tempdir):
"""Regression test for #10474."""

# Given a conf.py file with language = None
(tempdir / 'conf.py').write_text("language = None", encoding='utf-8')

# When we load conf.py into a Config object
cfg = Config.read(tempdir, {}, None)
cfg.init_values()

# Then the language is coerced to English
assert cfg.language == "en"


def test_conf_py_no_language(tempdir):
"""Regression test for #10474."""

# Given a conf.py file with no language attribute
(tempdir / 'conf.py').write_text("", encoding='utf-8')

# When we load conf.py into a Config object
cfg = Config.read(tempdir, {}, None)
cfg.init_values()

# Then the language is coerced to English
assert cfg.language == "en"