mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 00:04:42 +04:00
Deepcopy defaults to prevent weird references in yaml.
This commit is contained in:
parent
5a7044edcc
commit
817ec510c7
2 changed files with 10 additions and 1 deletions
|
|
@ -16,7 +16,9 @@ def extend_with_default(validator_class):
|
|||
|
||||
for property, subschema in properties.iteritems():
|
||||
if "default" in subschema:
|
||||
instance.setdefault(property, subschema["default"])
|
||||
instance.setdefault(
|
||||
property, copy.deepcopy(subschema["default"]),
|
||||
)
|
||||
|
||||
return jsonschema.validators.extend(
|
||||
validator_class, {"properties" : set_defaults},
|
||||
|
|
|
|||
|
|
@ -49,3 +49,10 @@ def test_apply_defaults_deep():
|
|||
},
|
||||
)
|
||||
assert ret == {'foo': {'bar': {'baz': 'herp'}}}
|
||||
|
||||
|
||||
def test_apply_defaults_copies():
|
||||
schema = {'properties': {'foo': {'default': []}}}
|
||||
ret1 = apply_defaults({}, schema)
|
||||
ret2 = apply_defaults({}, schema)
|
||||
assert ret1['foo'] is not ret2['foo']
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue