44from __future__ import annotations
55
66from collections import defaultdict , deque
7+ from collections .abc import Iterable , Mapping , MutableMapping
78from pprint import pformat
89from textwrap import dedent , indent
910from typing import ClassVar
@@ -297,9 +298,9 @@ class ErrorTree:
297298
298299 _instance = _unset
299300
300- def __init__ (self , errors = ()):
301- self .errors = {}
302- self ._contents = defaultdict (self .__class__ )
301+ def __init__ (self , errors : Iterable [ ValidationError ] = ()):
302+ self .errors : MutableMapping [ str , ValidationError ] = {}
303+ self ._contents : Mapping [ str , ErrorTree ] = defaultdict (self .__class__ )
303304
304305 for error in errors :
305306 container = self
@@ -309,7 +310,7 @@ def __init__(self, errors=()):
309310
310311 container ._instance = error .instance
311312
312- def __contains__ (self , index ):
313+ def __contains__ (self , index : str | int ):
313314 """
314315 Check whether ``instance[index]`` has any errors.
315316 """
@@ -328,7 +329,7 @@ def __getitem__(self, index):
328329 self ._instance [index ]
329330 return self ._contents [index ]
330331
331- def __setitem__ (self , index , value ):
332+ def __setitem__ (self , index : str | int , value : ErrorTree ):
332333 """
333334 Add an error to the tree at the given ``index``.
334335
@@ -343,7 +344,7 @@ def __setitem__(self, index, value):
343344 DeprecationWarning ,
344345 stacklevel = 2 ,
345346 )
346- self ._contents [index ] = value
347+ self ._contents [index ] = value # type: ignore[index]
347348
348349 def __iter__ (self ):
349350 """
0 commit comments