Skip to content

Commit a8c3b14

Browse files
committed
Fix one more Validator.evolve issue for downstream Validators.
Here for renamed attributes out of attrs-using classes. Refs: '#982 (comment)'
1 parent c2e86ee commit a8c3b14

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
v4.10.2
2+
-------
3+
4+
* Fix a second place where subclasses may have added attrs attributes (#982).
5+
16
v4.10.1
27
-------
38

jsonschema/tests/test_validators.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1488,12 +1488,14 @@ def test_evolve_with_subclass(self):
14881488
@attr.s
14891489
class OhNo(self.Validator):
14901490
foo = attr.ib(factory=lambda: [1, 2, 3])
1491+
_bar = attr.ib(default=37)
14911492

1492-
validator = OhNo({})
1493+
validator = OhNo({}, bar=12)
14931494
self.assertEqual(validator.foo, [1, 2, 3])
14941495

14951496
new = validator.evolve(schema={"type": "integer"})
14961497
self.assertEqual(new.foo, [1, 2, 3])
1498+
self.assertEqual(new._bar, 12)
14971499

14981500
def test_it_delegates_to_a_legacy_ref_resolver(self):
14991501
"""

jsonschema/validators.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,14 @@ def check_schema(cls, schema):
202202
raise exceptions.SchemaError.create_from(error)
203203

204204
def evolve(self, **changes):
205-
schema = changes.setdefault("schema", self.schema)
206-
NewValidator = validator_for(schema, default=self.__class__)
207-
208205
# Essentially reproduces attr.evolve, but may involve instantiating
209206
# a different class than this one.
210-
for field in attr.fields(Validator):
207+
cls = self.__class__
208+
209+
schema = changes.setdefault("schema", self.schema)
210+
NewValidator = validator_for(schema, default=cls)
211+
212+
for field in attr.fields(cls):
211213
if not field.init:
212214
continue
213215
attr_name = field.name # To deal with private attributes.

0 commit comments

Comments
 (0)