Skip to content

Commit 2c534dc

Browse files
authored
Improve annotation of jsonschema.validators.create (#8608)
1 parent c17c0d5 commit 2c534dc

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

stubs/jsonschema/jsonschema/validators.pyi

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
from _typeshed import SupportsKeysAndGetItem
2-
from collections.abc import Callable, Generator, Iterable, Mapping
2+
from collections.abc import Callable, Generator, Iterable, Iterator, Mapping
33
from typing import Any, ClassVar
44
from typing_extensions import TypeAlias
55

6+
from ._format import FormatChecker
7+
from ._types import TypeChecker
68
from ._utils import URIDict
9+
from .exceptions import ValidationError
10+
11+
# these type aliases do not exist at runtime, they're only defined here in the stub
12+
_JsonObject: TypeAlias = Mapping[str, Any]
13+
_JsonValue: TypeAlias = _JsonObject | list[Any] | str | int | float | bool | None
14+
_ValidatorCallback: TypeAlias = Callable[[Any, Any, _JsonValue, _JsonObject], Iterator[ValidationError]]
715

816
_Schema: TypeAlias = Mapping[str, Any]
917

@@ -33,13 +41,13 @@ class _Validator:
3341

3442
def validates(version: str) -> Callable[..., Any]: ...
3543
def create(
36-
meta_schema,
37-
validators=...,
44+
meta_schema: _Schema,
45+
validators: Mapping[str, _ValidatorCallback] | tuple[()] = ...,
3846
version: Any | None = ...,
39-
type_checker=...,
40-
format_checker=...,
41-
id_of=...,
42-
applicable_validators=...,
47+
type_checker: TypeChecker = ...,
48+
format_checker: FormatChecker = ...,
49+
id_of: Callable[[_Schema], str] = ...,
50+
applicable_validators: Callable[[_Schema], Iterable[tuple[str, _ValidatorCallback]]] = ...,
4351
) -> type[_Validator]: ...
4452
def extend(
4553
validator, validators=..., version: Any | None = ..., type_checker: Any | None = ..., format_checker: Any | None = ...

0 commit comments

Comments
 (0)