Skip to content

Commit

Permalink
Soft-deprecate ConfigItems instead of expanding it
Browse files Browse the repository at this point in the history
This undoes the addition of the `validate` parameter from ee84424.
It is OK to do because this was not released yet.
  • Loading branch information
oprypin committed Sep 24, 2022
1 parent dba48e1 commit 2263c50
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
8 changes: 3 additions & 5 deletions mkdocs/config/config_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,14 @@ def run_validation(self, value):

class ConfigItems(ListOfItems):
"""
Config Items Option
Deprecated: Use `ListOfItems(SubConfig(...))` instead of `ConfigItems(...)`.
Validates a list of mappings that all must match the same set of
options.
"""

def __init__(
self, *config_options: PlainConfigSchemaItem, required: bool = False, validate: bool = False
):
super().__init__(SubConfig(*config_options, validate=validate))
def __init__(self, *config_options: PlainConfigSchemaItem, required: bool = False):
super().__init__(SubConfig(*config_options))
self.required = required


Expand Down
20 changes: 12 additions & 8 deletions mkdocs/tests/config/config_options_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,8 @@ class Schema:
conf = self.get_config(Schema, {'option': {'cc': 'foo'}})
self.assertEqual(conf['option'], {'cc': 'foo'})


class ConfigItemsTest(TestCase):
def test_subconfig_with_multiple_items(self):
# This had a bug where subsequent items would get merged into the same dict.
class Schema:
Expand All @@ -1270,13 +1272,13 @@ class Schema:
)
self.assertEqual(conf['the_items'], [{'value': 'a'}, {'value': 'b'}])


class ConfigItemsTest(TestCase):
def test_optional(self):
class Schema:
sub = c.ConfigItems(
('opt', c.Type(int)),
validate=True,
sub = c.ListOfItems(
c.SubConfig(
('opt', c.Type(int)),
validate=True,
)
)

conf = self.get_config(Schema, {})
Expand All @@ -1295,9 +1297,11 @@ class Schema:

def test_required(self):
class Schema:
sub = c.ConfigItems(
('opt', c.Type(int, required=True)),
validate=True,
sub = c.ListOfItems(
c.SubConfig(
('opt', c.Type(int, required=True)),
validate=True,
)
)

conf = self.get_config(Schema, {})
Expand Down

0 comments on commit 2263c50

Please sign in to comment.