mirror of
https://github.com/mkdocs/mkdocs.git
synced 2026-03-27 09:58:31 +07:00
Fix propagating warnings from sub-items of ListOfItems
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user