From 0880741ba3b24c5da1b67dd37217ed830df1a6e4 Mon Sep 17 00:00:00 2001 From: Eddie Darling Date: Tue, 6 Dec 2022 13:08:11 -0800 Subject: [PATCH] Update jsonschema protocols.pyi (#9295) These take in an instance, which need not be a JSON object. They could for example be arrays. See [this example](https://python-jsonschema.readthedocs.io/en/stable/api/jsonschema/protocols/#jsonschema.protocols.Validator.iter_errors) on the jsonschema docs. ```python >>> schema = {"maxItems" : 2} >>> Draft202012Validator(schema).is_valid([2, 3, 4]) False ``` --- stubs/jsonschema/jsonschema/protocols.pyi | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/stubs/jsonschema/jsonschema/protocols.pyi b/stubs/jsonschema/jsonschema/protocols.pyi index 10e03dabf..7a3c6e145 100644 --- a/stubs/jsonschema/jsonschema/protocols.pyi +++ b/stubs/jsonschema/jsonschema/protocols.pyi @@ -1,11 +1,14 @@ -from collections.abc import Iterator +from collections.abc import Iterator, Mapping, Sequence from typing import Any, ClassVar, Protocol +from typing_extensions import TypeAlias from jsonschema._format import FormatChecker from jsonschema._types import TypeChecker from jsonschema.exceptions import ValidationError from jsonschema.validators import RefResolver +_JsonParameter: TypeAlias = str | int | float | bool | None | Mapping[str, _JsonParameter] | Sequence[_JsonParameter] + class Validator(Protocol): META_SCHEMA: ClassVar[dict[Any, Any]] VALIDATORS: ClassVar[dict[Any, Any]] @@ -17,8 +20,8 @@ class Validator(Protocol): ) -> None: ... @classmethod def check_schema(cls, schema: dict[Any, Any]) -> None: ... - def is_type(self, instance: Any, type: str) -> bool: ... - def is_valid(self, instance: dict[Any, Any]) -> bool: ... - def iter_errors(self, instance: dict[Any, Any]) -> Iterator[ValidationError]: ... - def validate(self, instance: dict[Any, Any]) -> None: ... + def is_type(self, instance: _JsonParameter, type: str) -> bool: ... + def is_valid(self, instance: _JsonParameter) -> bool: ... + def iter_errors(self, instance: _JsonParameter) -> Iterator[ValidationError]: ... + def validate(self, instance: _JsonParameter) -> None: ... def evolve(self, **kwargs) -> Validator: ...