Skip to content

Commit

Permalink
Fix case where language isn't set
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed May 27, 2022
1 parent 20a1775 commit 57e4a2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sphinx/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def read(cls, confdir: str, overrides: Dict = None, tags: Tags = None) -> "Confi

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

return cls(namespace, overrides or {})
Expand Down
14 changes: 14 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,17 @@ def test_conf_py_language_none(tempdir):

# 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"

0 comments on commit 57e4a2f

Please sign in to comment.