Skip to content

Commit 7215038

Browse files
committed
Fix mypy types for protocols.Validator
iter_errors returns an iterable, and doesn't guarantee it's an iterator (this is present in the text documentation). And instances are any Python object, not just dicts. (CC @sirosen just FYI and in case I made some silly error).
1 parent cf3ed23 commit 7215038

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

jsonschema/protocols.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from __future__ import annotations
99

10-
from typing import TYPE_CHECKING, Any, ClassVar, Iterator
10+
from typing import TYPE_CHECKING, Any, ClassVar, Iterable
1111
import sys
1212

1313
# doing these imports with `try ... except ImportError` doesn't pass mypy
@@ -113,7 +113,7 @@ def is_type(self, instance: Any, type: str) -> bool:
113113
is not a known type.
114114
"""
115115

116-
def is_valid(self, instance: dict) -> bool:
116+
def is_valid(self, instance: Any) -> bool:
117117
"""
118118
Check if the instance is valid under the current `schema`.
119119
@@ -124,7 +124,7 @@ def is_valid(self, instance: dict) -> bool:
124124
False
125125
"""
126126

127-
def iter_errors(self, instance: dict) -> Iterator[ValidationError]:
127+
def iter_errors(self, instance: Any) -> Iterable[ValidationError]:
128128
r"""
129129
Lazily yield each of the validation errors in the given instance.
130130
@@ -143,7 +143,7 @@ def iter_errors(self, instance: dict) -> Iterator[ValidationError]:
143143
[2, 3, 4] is too long
144144
"""
145145

146-
def validate(self, instance: dict) -> None:
146+
def validate(self, instance: Any) -> None:
147147
"""
148148
Check if the instance is valid under the current `schema`.
149149

0 commit comments

Comments
 (0)