File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ v4.20.0
2
+ =======
3
+
4
+ * ``jsonschema.exceptions.ErrorTree.__setitem__ `` is now deprecated.
5
+ More broadly, in general users of ``jsonschema `` should never be mutating objects owned by the library.
6
+
1
7
v4.19.2
2
8
=======
3
9
Original file line number Diff line number Diff line change @@ -331,7 +331,18 @@ def __getitem__(self, index):
331
331
def __setitem__ (self , index , value ):
332
332
"""
333
333
Add an error to the tree at the given ``index``.
334
+
335
+ .. deprecated:: v4.20.0
336
+
337
+ Setting items on an `ErrorTree` is deprecated without replacement.
338
+ To populate a tree, provide all of its suberrors when you construct
339
+ the tree.
334
340
"""
341
+ warnings .warn (
342
+ "ErrorTree.__setitem__ is deprecated without replacement." ,
343
+ DeprecationWarning ,
344
+ stacklevel = 2 ,
345
+ )
335
346
self ._contents [index ] = value
336
347
337
348
def __iter__ (self ):
Original file line number Diff line number Diff line change @@ -51,6 +51,22 @@ def test_import_ErrorTree(self):
51
51
self .assertEqual (ErrorTree , exceptions .ErrorTree )
52
52
self .assertEqual (w .filename , __file__ )
53
53
54
+ def test_ErrorTree_setitem (self ):
55
+ """
56
+ As of v4.20.0, setting items on an ErrorTree is deprecated.
57
+ """
58
+
59
+ e = exceptions .ValidationError ("some error" , path = ["foo" ])
60
+ tree = exceptions .ErrorTree ()
61
+ subtree = exceptions .ErrorTree (errors = [e ])
62
+
63
+ message = "ErrorTree.__setitem__ is "
64
+ with self .assertWarnsRegex (DeprecationWarning , message ) as w :
65
+ tree ["foo" ] = subtree
66
+
67
+ self .assertEqual (tree ["foo" ], subtree )
68
+ self .assertEqual (w .filename , __file__ )
69
+
54
70
def test_import_FormatError (self ):
55
71
"""
56
72
As of v4.18.0, importing FormatError from the package root is
You can’t perform that action at this time.
0 commit comments