diff --git a/voluptuous/__init__.py b/voluptuous/__init__.py index d00baa1..3725e67 100644 --- a/voluptuous/__init__.py +++ b/voluptuous/__init__.py @@ -73,6 +73,7 @@ ... 'Users': {'snmp_community': 'monkey'}}}} True """ + # flake8: noqa # fmt: off from voluptuous.schema_builder import * diff --git a/voluptuous/schema_builder.py b/voluptuous/schema_builder.py index 4b95cc7..cdeb514 100644 --- a/voluptuous/schema_builder.py +++ b/voluptuous/schema_builder.py @@ -1,4 +1,3 @@ - # fmt: off from __future__ import annotations @@ -363,10 +362,10 @@ def validate_mapping(path, iterable, out): if remove_key: # remove key continue - elif error: - errors.append(error) elif self.extra == ALLOW_EXTRA: out[key] = value + elif error: + errors.append(error) elif self.extra != REMOVE_EXTRA: errors.append(er.Invalid('extra keys not allowed', key_path)) # else REMOVE_EXTRA: ignore the key so it's removed from output diff --git a/voluptuous/tests/tests.py b/voluptuous/tests/tests.py index 8fa1883..77110d8 100644 --- a/voluptuous/tests/tests.py +++ b/voluptuous/tests/tests.py @@ -1704,6 +1704,23 @@ def as_int(a): assert str(ctx.value.errors[1]) == "expecting a number @ data['four']" +def test_key3(): + schema = Schema( + { + Any("name", "area"): str, + "domain": str, + }, + extra=ALLOW_EXTRA, + ) + schema( + { + "name": "one", + "domain": "two", + "additional_key": "extra", + } + ) + + def test_coerce_enum(): """Test Coerce Enum"""