Raise `ThemeError` for invalid theme sections

This commit is contained in:
Adam Turner
2024-07-20 18:51:10 +01:00
parent 9f886cc878
commit af82d70c60
3 changed files with 7 additions and 8 deletions

View File

@@ -41,6 +41,8 @@ Incompatible changes
Patch by Adam Turner.
* #12593: Raise an error for invalid :confval:`html_sidebars` values.
Patch by Adam Turner.
* #12593: Raise an error in :py:func:`!Theme.get_config` for invalid sections.
Patch by Adam Turner.
Deprecated
----------

View File

@@ -121,17 +121,11 @@ class Theme:
elif section == 'options':
value = self._options.get(name, default)
else:
# https://github.com/sphinx-doc/sphinx/issues/12305
# For backwards compatibility when attempting to read a value
# from an unsupported configuration section.
# xref: RemovedInSphinx80Warning
msg = __(
'Theme configuration sections other than [theme] and [options] '
'are not supported, returning the default value instead '
'(tried to get a value from %r)'
'are not supported (tried to get a value from %r).'
)
logger.info(msg, section)
value = default
raise ThemeError(msg)
if value is _NO_DEFAULT:
msg = __('setting %s.%s occurs in none of the searched theme configs') % (
section,

View File

@@ -72,6 +72,9 @@ def test_theme_api(app, status, warning):
assert theme.get_config('theme', 'foobar', 'def') == 'def'
with pytest.raises(ThemeError):
theme.get_config('theme', 'foobar')
# nonexisting section
with pytest.raises(ThemeError):
theme.get_config('foobar', 'foobar')
# options API