diff --git a/CHANGES.rst b/CHANGES.rst index 3319e6860..fc5143fcd 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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 ---------- diff --git a/sphinx/theming.py b/sphinx/theming.py index 29571781e..bd7678fc6 100644 --- a/sphinx/theming.py +++ b/sphinx/theming.py @@ -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, diff --git a/tests/test_theming/test_theming.py b/tests/test_theming/test_theming.py index 680465ba4..5b236bcc3 100644 --- a/tests/test_theming/test_theming.py +++ b/tests/test_theming/test_theming.py @@ -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