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+
17v4.19.2
28=======
39
Original file line number Diff line number Diff line change @@ -331,7 +331,18 @@ def __getitem__(self, index):
331331 def __setitem__ (self , index , value ):
332332 """
333333 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.
334340 """
341+ warnings .warn (
342+ "ErrorTree.__setitem__ is deprecated without replacement." ,
343+ DeprecationWarning ,
344+ stacklevel = 2 ,
345+ )
335346 self ._contents [index ] = value
336347
337348 def __iter__ (self ):
Original file line number Diff line number Diff line change @@ -51,6 +51,22 @@ def test_import_ErrorTree(self):
5151 self .assertEqual (ErrorTree , exceptions .ErrorTree )
5252 self .assertEqual (w .filename , __file__ )
5353
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+
5470 def test_import_FormatError (self ):
5571 """
5672 As of v4.18.0, importing FormatError from the package root is
You can’t perform that action at this time.
0 commit comments