From 9fda9dd7e62aa8e0519f516b08440369d2da71de Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Mon, 24 Jan 2022 15:54:52 +0100 Subject: [PATCH 1/5] Annotate parts of jsonschema.validators Bump jsonschema version to 4.4.* --- stubs/jsonschema/METADATA.toml | 2 +- stubs/jsonschema/jsonschema/validators.pyi | 54 ++++++++++++++++------ 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/stubs/jsonschema/METADATA.toml b/stubs/jsonschema/METADATA.toml index a51d6edb1ccd..2e800d80f5da 100644 --- a/stubs/jsonschema/METADATA.toml +++ b/stubs/jsonschema/METADATA.toml @@ -1 +1 @@ -version = "4.3.*" +version = "4.4.*" diff --git a/stubs/jsonschema/jsonschema/validators.pyi b/stubs/jsonschema/jsonschema/validators.pyi index 7829021784ac..6bc40d8bee17 100644 --- a/stubs/jsonschema/jsonschema/validators.pyi +++ b/stubs/jsonschema/jsonschema/validators.pyi @@ -1,28 +1,54 @@ -from typing import Any, Callable +from _typeshed import SupportsKeysAndGetItem +from collections.abc import Callable, Generator, Mapping +from typing import Any, ClassVar + +# This class does not exist runtime. Compatible classes are created at +# runtime by create(). +class _Validator: + VALIDATORS: ClassVar[dict[Any, Any]] + META_SCHEMA: ClassVar[dict[Any, Any]] + TYPE_CHECKER: Any + @staticmethod + def ID_OF(): ... + schema: Any + resolver: Any + format_checker: Any + evolve: Any + @classmethod + def check_schema(cls, schema) -> None: ... + def iter_errors(self, instance, _schema: Any | None = ...) -> Generator[Any, None, None]: ... + def descend(self, instance, schema, path: Any | None = ..., schema_path: Any | None = ...) -> Generator[Any, None, None]: ... + def validate(self, *args, **kwargs) -> None: ... + def is_type(self, instance, type): ... + def is_valid(self, instance, _schema: Any | None = ...) -> bool: ... def validates(version: str) -> Callable[..., Any]: ... -def create(meta_schema, validators=..., version: Any | None = ..., type_checker=..., id_of=..., applicable_validators=...): ... +def create( + meta_schema, validators=..., version: Any | None = ..., type_checker=..., id_of=..., applicable_validators=... +) -> type[_Validator]: ... def extend(validator, validators=..., version: Any | None = ..., type_checker: Any | None = ...): ... -Draft3Validator: Any -Draft4Validator: Any -Draft6Validator: Any -Draft7Validator: Any -Draft201909Validator: Any -Draft202012Validator: Any +Draft3Validator: type[_Validator] +Draft4Validator: type[_Validator] +Draft6Validator: type[_Validator] +Draft7Validator: type[_Validator] +Draft201909Validator: type[_Validator] +Draft202012Validator: type[_Validator] + +_Handler = Callable[[str], Any] class RefResolver: referrer: Any cache_remote: Any - handlers: Any + handlers: dict[str, _Handler] store: Any def __init__( self, - base_uri, - referrer, - store=..., + base_uri: str, + referrer: Any, + store: Mapping[str, Any] = ..., cache_remote: bool = ..., - handlers=..., + handlers: SupportsKeysAndGetItem[str, _Handler] | Iterable[tuple[str, _Handler]] = ..., urljoin_cache: Any | None = ..., remote_cache: Any | None = ..., ) -> None: ... @@ -41,5 +67,5 @@ class RefResolver: def resolve_fragment(self, document, fragment): ... def resolve_remote(self, uri): ... -def validate(instance, schema, cls: Any | None = ..., *args, **kwargs) -> None: ... +def validate(instance: object, schema: object, cls: type[_Validator] | None = ..., *args: Any, **kwargs: Any) -> None: ... def validator_for(schema, default=...): ... From e5fdfb30b76494ee1550e980af9de1d779032b91 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Mon, 24 Jan 2022 15:58:42 +0100 Subject: [PATCH 2/5] Add missing import --- stubs/jsonschema/jsonschema/validators.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/jsonschema/jsonschema/validators.pyi b/stubs/jsonschema/jsonschema/validators.pyi index 6bc40d8bee17..fc6d03794729 100644 --- a/stubs/jsonschema/jsonschema/validators.pyi +++ b/stubs/jsonschema/jsonschema/validators.pyi @@ -1,5 +1,5 @@ from _typeshed import SupportsKeysAndGetItem -from collections.abc import Callable, Generator, Mapping +from collections.abc import Callable, Generator, Iterable, Mapping from typing import Any, ClassVar # This class does not exist runtime. Compatible classes are created at From 208fdebe0ee56754a8070945d762fe5fd70d2a2c Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Mon, 24 Jan 2022 16:09:34 +0100 Subject: [PATCH 3/5] Annotate URIDict --- stubs/jsonschema/jsonschema/_utils.pyi | 19 ++++++++++--------- stubs/jsonschema/jsonschema/validators.pyi | 10 ++++++---- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/stubs/jsonschema/jsonschema/_utils.pyi b/stubs/jsonschema/jsonschema/_utils.pyi index 448be7e91cfa..2b20d72a5c39 100644 --- a/stubs/jsonschema/jsonschema/_utils.pyi +++ b/stubs/jsonschema/jsonschema/_utils.pyi @@ -1,14 +1,15 @@ -from typing import Any, Generator, Iterable, Mapping, MutableMapping, Sized +from _typeshed import SupportsKeysAndGetItem +from typing import Any, Generator, Iterable, Iterator, Mapping, MutableMapping, Sized -class URIDict(MutableMapping[Any, Any]): +class URIDict(MutableMapping[str, str]): def normalize(self, uri: str) -> str: ... - store: dict[Any, Any] - def __init__(self, *args, **kwargs) -> None: ... - def __getitem__(self, uri): ... - def __setitem__(self, uri, value) -> None: ... - def __delitem__(self, uri) -> None: ... - def __iter__(self): ... - def __len__(self): ... + store: dict[str, str] + def __init__(self, __m: SupportsKeysAndGetItem[str, str] | Iterable[tuple[str, str]], **kwargs: str) -> None: ... + def __getitem__(self, uri: str) -> str: ... + def __setitem__(self, uri: str, value: str) -> None: ... + def __delitem__(self, uri: str) -> None: ... + def __iter__(self) -> Iterator[str]: ... + def __len__(self) -> int: ... class Unset: ... diff --git a/stubs/jsonschema/jsonschema/validators.pyi b/stubs/jsonschema/jsonschema/validators.pyi index fc6d03794729..516064e0f6a0 100644 --- a/stubs/jsonschema/jsonschema/validators.pyi +++ b/stubs/jsonschema/jsonschema/validators.pyi @@ -2,6 +2,8 @@ from _typeshed import SupportsKeysAndGetItem from collections.abc import Callable, Generator, Iterable, Mapping from typing import Any, ClassVar +from ._utils import URIDict + # This class does not exist runtime. Compatible classes are created at # runtime by create(). class _Validator: @@ -38,15 +40,15 @@ Draft202012Validator: type[_Validator] _Handler = Callable[[str], Any] class RefResolver: - referrer: Any + referrer: str cache_remote: Any handlers: dict[str, _Handler] - store: Any + store: URIDict def __init__( self, base_uri: str, - referrer: Any, - store: Mapping[str, Any] = ..., + referrer: str, + store: SupportsKeysAndGetItem[str, str] | Iterable[tuple[str, str]] = ..., cache_remote: bool = ..., handlers: SupportsKeysAndGetItem[str, _Handler] | Iterable[tuple[str, _Handler]] = ..., urljoin_cache: Any | None = ..., From da404be1d442a92e3100892f8b61737114e0b143 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Mon, 24 Jan 2022 16:10:53 +0100 Subject: [PATCH 4/5] Remove unused import --- stubs/jsonschema/jsonschema/validators.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/jsonschema/jsonschema/validators.pyi b/stubs/jsonschema/jsonschema/validators.pyi index 516064e0f6a0..3516338a21ca 100644 --- a/stubs/jsonschema/jsonschema/validators.pyi +++ b/stubs/jsonschema/jsonschema/validators.pyi @@ -1,5 +1,5 @@ from _typeshed import SupportsKeysAndGetItem -from collections.abc import Callable, Generator, Iterable, Mapping +from collections.abc import Callable, Generator, Iterable from typing import Any, ClassVar from ._utils import URIDict From d5bf970ebe7e22d90b1f0afae259f971fa461daa Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Mon, 24 Jan 2022 07:35:26 -0800 Subject: [PATCH 5/5] Update stubs/jsonschema/jsonschema/validators.pyi --- stubs/jsonschema/jsonschema/validators.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/jsonschema/jsonschema/validators.pyi b/stubs/jsonschema/jsonschema/validators.pyi index 3516338a21ca..245e33118831 100644 --- a/stubs/jsonschema/jsonschema/validators.pyi +++ b/stubs/jsonschema/jsonschema/validators.pyi @@ -4,7 +4,7 @@ from typing import Any, ClassVar from ._utils import URIDict -# This class does not exist runtime. Compatible classes are created at +# This class does not exist at runtime. Compatible classes are created at # runtime by create(). class _Validator: VALIDATORS: ClassVar[dict[Any, Any]]