This commit is contained in:
Otto Winter committed 2019-02-15 10:57:02 +01:00
1 parent b7607ff472
commit f6ae054e9f
2 files changed
+12 -5

No files matched your search

+4 -1
View File
@@ -636,7 +636,9 @@ def key_dependency(key, dependency):
# Schemas
class HASchema(vol.Schema):
"""Schema class that allows us to mark PREVENT_EXTRA errors as warnings."""
def __call__(self, data):
"""Override __call__ to mark PREVENT_EXTRA as warning."""
try:
return super().__call__(data)
except vol.Invalid as orig_err:
@@ -645,6 +647,7 @@ class HASchema(vol.Schema):
# orig_error is of type vol.MultipleInvalid (see super __call__)
assert isinstance(orig_err, vol.MultipleInvalid)
# pylint: disable=no-member
# If it fails with PREVENT_EXTRA, try with ALLOW_EXTRA
self.extra = vol.ALLOW_EXTRA
# In case it still fails the following will raise
@@ -675,7 +678,7 @@ class HASchema(vol.Schema):
return validated
def extend(self, schema, required=None, extra=None):
"""Extend this schema and convert it to HASchema if necessary"""
"""Extend this schema and convert it to HASchema if necessary."""
ret = super().extend(schema, required=required, extra=extra)
if extra is not None:
return ret