Fix propagating warnings from sub-items of ListOfItems

This commit is contained in:
Oleh Prypin
2023-05-30 21:58:39 +02:00
parent c4db02b586
commit fce89f71a9
2 changed files with 15 additions and 1 deletions

View File

@@ -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:

View File

@@ -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: