Skip to content

Commit

Permalink
Minor typing tweaks in the exceptions module.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian committed Oct 31, 2023
1 parent 65877a1 commit 11e2302
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions jsonschema/exceptions.py
Expand Up @@ -4,6 +4,7 @@
from __future__ import annotations

from collections import defaultdict, deque
from collections.abc import Iterable, Mapping, MutableMapping
from pprint import pformat
from textwrap import dedent, indent
from typing import ClassVar
Expand Down Expand Up @@ -297,9 +298,9 @@ class ErrorTree:

_instance = _unset

def __init__(self, errors=()):
self.errors = {}
self._contents = defaultdict(self.__class__)
def __init__(self, errors: Iterable[ValidationError] = ()):
self.errors: MutableMapping[str, ValidationError] = {}
self._contents: Mapping[str, ErrorTree] = defaultdict(self.__class__)

for error in errors:
container = self
Expand All @@ -309,7 +310,7 @@ def __init__(self, errors=()):

container._instance = error.instance

def __contains__(self, index):
def __contains__(self, index: str | int):
"""
Check whether ``instance[index]`` has any errors.
"""
Expand All @@ -328,7 +329,7 @@ def __getitem__(self, index):
self._instance[index]
return self._contents[index]

def __setitem__(self, index, value):
def __setitem__(self, index: str | int, value: ErrorTree):
"""
Add an error to the tree at the given ``index``.
Expand All @@ -343,7 +344,7 @@ def __setitem__(self, index, value):
DeprecationWarning,
stacklevel=2,
)
self._contents[index] = value
self._contents[index] = value # type: ignore[index]

def __iter__(self):
"""
Expand Down

0 comments on commit 11e2302

Please sign in to comment.