Fix crash when mkdocs_theme.yml is empty

Fixes #3699
This commit is contained in:
Thea Flowers
2024-05-09 10:27:04 -04:00
parent 30e8142315
commit cd80116339
2 changed files with 22 additions and 0 deletions

View File

@@ -104,3 +104,22 @@ class ThemeTests(unittest.TestCase):
],
)
self.assertEqual(theme.static_templates, {'sitemap.xml', 'child.html', 'parent.html'})
def test_empty_config_file(self):
# Test for themes with *empty* mkdocs_theme.yml.
# See https://github.com/mkdocs/mkdocs/issues/3699
m = mock.Mock(
# yaml.load returns "None" for an empty file
side_effect=[None]
)
with mock.patch('yaml.load', m) as m:
theme = Theme(name='mkdocs')
# Should only have the default name and locale __vars set in
# Theme.__init__()
self.assertEqual(
dict(theme),
{
'name': 'mkdocs',
'locale': parse_locale('en'),
},
)

View File

@@ -138,6 +138,9 @@ class Theme(MutableMapping[str, Any]):
f"Please upgrade to a current version of the theme."
)
if theme_config is None:
theme_config = {}
log.debug(f"Loaded theme configuration for '{name}' from '{file_path}': {theme_config}")
if parent_theme := theme_config.pop('extends', None):