4
4
from __future__ import annotations
5
5
6
6
from collections import defaultdict , deque
7
+ from collections .abc import Iterable , Mapping , MutableMapping
7
8
from pprint import pformat
8
9
from textwrap import dedent , indent
9
10
from typing import ClassVar
@@ -297,9 +298,9 @@ class ErrorTree:
297
298
298
299
_instance = _unset
299
300
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__ )
303
304
304
305
for error in errors :
305
306
container = self
@@ -309,7 +310,7 @@ def __init__(self, errors=()):
309
310
310
311
container ._instance = error .instance
311
312
312
- def __contains__ (self , index ):
313
+ def __contains__ (self , index : str | int ):
313
314
"""
314
315
Check whether ``instance[index]`` has any errors.
315
316
"""
@@ -328,7 +329,7 @@ def __getitem__(self, index):
328
329
self ._instance [index ]
329
330
return self ._contents [index ]
330
331
331
- def __setitem__ (self , index , value ):
332
+ def __setitem__ (self , index : str | int , value : ErrorTree ):
332
333
"""
333
334
Add an error to the tree at the given ``index``.
334
335
@@ -343,7 +344,7 @@ def __setitem__(self, index, value):
343
344
DeprecationWarning ,
344
345
stacklevel = 2 ,
345
346
)
346
- self ._contents [index ] = value
347
+ self ._contents [index ] = value # type: ignore[index]
347
348
348
349
def __iter__ (self ):
349
350
"""
0 commit comments