From fce89f71a9d400a55d9b61ebf0c651828c64a0cb Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Tue, 30 May 2023 21:58:39 +0200 Subject: [PATCH] Fix propagating warnings from sub-items of `ListOfItems` --- mkdocs/config/config_options.py | 3 ++- mkdocs/tests/config/config_options_tests.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/mkdocs/config/config_options.py b/mkdocs/config/config_options.py index 9f160e82..ee75b047 100644 --- a/mkdocs/config/config_options.py +++ b/mkdocs/config/config_options.py @@ -95,7 +95,7 @@ class SubConfig(Generic[SomeConfig], BaseConfigOption[SomeConfig]): if self._do_validation: # Capture errors and warnings - self.warnings = [f"Sub-option '{key}': {msg}" for key, msg in warnings] + self.warnings.extend(f"Sub-option '{key}': {msg}" for key, msg in warnings) if failed: # Get the first failing one key, err = failed[0] @@ -188,6 +188,7 @@ class ListOfItems(Generic[T], BaseConfigOption[List[T]]): fake_keys = [f'{parent_key_name}[{i}]' for i in range(len(value))] fake_config.data = dict(zip(fake_keys, value)) + self.option_type.warnings = self.warnings for key_name in fake_config: self.option_type.pre_validation(fake_config, key_name) for key_name in fake_config: diff --git a/mkdocs/tests/config/config_options_tests.py b/mkdocs/tests/config/config_options_tests.py index 952f4ce9..f82a1de9 100644 --- a/mkdocs/tests/config/config_options_tests.py +++ b/mkdocs/tests/config/config_options_tests.py @@ -678,6 +678,19 @@ class ListOfItemsTest(TestCase): with self.expect_error(option="'asdf' is not a valid port"): self.get_config(Schema, {'option': ["localhost:8000", "1.2.3.4:asdf"]}) + def test_warning(self) -> None: + class Schema(Config): + option = c.ListOfItems(c.Deprecated()) + + self.get_config( + Schema, + {'option': ['a']}, + warnings=dict( + option="The configuration option 'option[0]' has been " + "deprecated and will be removed in a future release." + ), + ) + class FilesystemObjectTest(TestCase): def test_valid_dir(self) -> None: