From f100dda3faefdb47186249ca2fb3394b591aa961 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Tue, 15 Aug 2023 16:42:20 +0200 Subject: [PATCH 1/4] Bump jsonschema to 4.19.* --- stubs/jsonschema/METADATA.toml | 3 +- stubs/jsonschema/jsonschema/_typing.pyi | 13 ++++++ stubs/jsonschema/jsonschema/_utils.pyi | 1 - stubs/jsonschema/jsonschema/validators.pyi | 51 ++++++++++++++-------- 4 files changed, 48 insertions(+), 20 deletions(-) create mode 100644 stubs/jsonschema/jsonschema/_typing.pyi diff --git a/stubs/jsonschema/METADATA.toml b/stubs/jsonschema/METADATA.toml index 8586b7fa003c..f6c4a4dca2b5 100644 --- a/stubs/jsonschema/METADATA.toml +++ b/stubs/jsonschema/METADATA.toml @@ -1,5 +1,6 @@ -version = "4.17.*" +version = "4.19.*" upstream_repository = "https://github.com/python-jsonschema/jsonschema" +requires = ["referencing"] partial_stub = true [tool.stubtest] diff --git a/stubs/jsonschema/jsonschema/_typing.pyi b/stubs/jsonschema/jsonschema/_typing.pyi new file mode 100644 index 000000000000..bf096c3fa078 --- /dev/null +++ b/stubs/jsonschema/jsonschema/_typing.pyi @@ -0,0 +1,13 @@ +from collections.abc import Callable, Iterable +from typing import Any, Protocol +from typing_extensions import TypeAlias + +from jsonschema.protocols import Validator +from referencing.jsonschema import Schema + +class SchemaKeywordValidator(Protocol): + def __call__(self, validator: Validator, value: Any, instance: Any, schema: Schema) -> None: ... + +id_of: TypeAlias = Callable[[Schema], str | None] # noqa: Y042 + +ApplicableValidators: TypeAlias = Callable[[Schema], Iterable[tuple[str, Any]]] diff --git a/stubs/jsonschema/jsonschema/_utils.pyi b/stubs/jsonschema/jsonschema/_utils.pyi index e00eb7c25f88..fd0207bd916e 100644 --- a/stubs/jsonschema/jsonschema/_utils.pyi +++ b/stubs/jsonschema/jsonschema/_utils.pyi @@ -13,7 +13,6 @@ class URIDict(MutableMapping[str, str]): class Unset: ... -def load_schema(name): ... def format_as_index(container: str, indices) -> str: ... def find_additional_properties( instance: Iterable[Incomplete], schema: Mapping[Incomplete, Incomplete] diff --git a/stubs/jsonschema/jsonschema/validators.pyi b/stubs/jsonschema/jsonschema/validators.pyi index 47ace89da529..72ef1f6cfcbe 100644 --- a/stubs/jsonschema/jsonschema/validators.pyi +++ b/stubs/jsonschema/jsonschema/validators.pyi @@ -4,6 +4,9 @@ from contextlib import contextmanager from typing import Any, ClassVar from typing_extensions import TypeAlias +from referencing.jsonschema import Schema, SchemaRegistry +from referencing.typing import URI + from ._format import FormatChecker from ._types import TypeChecker from ._utils import Unset, URIDict @@ -14,8 +17,6 @@ _JsonObject: TypeAlias = Mapping[str, Any] _JsonValue: TypeAlias = _JsonObject | list[Any] | str | int | float | bool | None _ValidatorCallback: TypeAlias = Callable[[Any, Any, _JsonValue, _JsonObject], Iterator[ValidationError]] -_Schema: TypeAlias = Mapping[str, Any] - # This class does not exist at runtime. Compatible classes are created at # runtime by create(). class _Validator: @@ -24,31 +25,45 @@ class _Validator: TYPE_CHECKER: ClassVar[Incomplete] FORMAT_CHECKER: ClassVar[Incomplete] @staticmethod - def ID_OF(schema: _Schema) -> str: ... - schema: _Schema - resolver: Incomplete - format_checker: Incomplete - evolve: Incomplete - def __init__(self, schema: _Schema, resolver: Incomplete | None = ..., format_checker: Incomplete | None = ...) -> None: ... + def ID_OF(contents: Schema) -> URI | None: ... + schema: Schema + format_checker: FormatChecker | None + def __init__( + self, + schema: Schema, + resolver: Incomplete | None = None, + format_checker: FormatChecker | None = None, + *, + registry: SchemaRegistry = ..., + _resolver: Incomplete | None = None, + ) -> None: ... @classmethod - def check_schema(cls, schema: _Schema, format_checker: FormatChecker | Unset = ...) -> None: ... - def iter_errors(self, instance, _schema: _Schema | None = ...) -> Generator[Incomplete, None, None]: ... + def check_schema(cls, schema: Schema, format_checker: FormatChecker | Unset = ...) -> None: ... + @property + def resolver(self): ... + def evolve(self, **changes) -> _Validator: ... + def iter_errors(self, instance, _schema: Schema | None = ...) -> Generator[Incomplete, None, None]: ... def descend( - self, instance, schema: _Schema, path: Incomplete | None = ..., schema_path: Incomplete | None = ... + self, + instance, + schema: Schema, + path: Incomplete | None = ..., + schema_path: Incomplete | None = ..., + resolver: Incomplete | None = None, ) -> Generator[Incomplete, None, None]: ... def validate(self, *args, **kwargs) -> None: ... def is_type(self, instance, type): ... - def is_valid(self, instance, _schema: _Schema | None = ...) -> bool: ... + def is_valid(self, instance, _schema: Schema | None = ...) -> bool: ... def validates(version: str) -> Callable[..., Incomplete]: ... def create( - meta_schema: _Schema, + meta_schema: Schema, validators: Mapping[str, _ValidatorCallback] | tuple[()] = (), version: Incomplete | None = None, type_checker: TypeChecker = ..., format_checker: FormatChecker = ..., - id_of: Callable[[_Schema], str] = ..., - applicable_validators: Callable[[_Schema], Iterable[tuple[str, _ValidatorCallback]]] = ..., + id_of: Callable[[Schema], str] = ..., + applicable_validators: Callable[[Schema], Iterable[tuple[str, _ValidatorCallback]]] = ..., ) -> type[_Validator]: ... def extend( validator, @@ -84,7 +99,7 @@ class RefResolver: remote_cache: Incomplete | None = None, ) -> None: ... @classmethod - def from_schema(cls, schema: _Schema, id_of=..., *args, **kwargs): ... + def from_schema(cls, schema: Schema, id_of=..., *args, **kwargs): ... def push_scope(self, scope) -> None: ... def pop_scope(self) -> None: ... @property @@ -100,5 +115,5 @@ class RefResolver: def resolve_fragment(self, document, fragment): ... def resolve_remote(self, uri): ... -def validate(instance: object, schema: _Schema, cls: type[_Validator] | None = None, *args: Any, **kwargs: Any) -> None: ... -def validator_for(schema: _Schema | bool, default=...): ... +def validate(instance: object, schema: Schema, cls: type[_Validator] | None = None, *args: Any, **kwargs: Any) -> None: ... +def validator_for(schema: Schema | bool, default=...): ... From 3deed403f2f09f6f2739e8708513c9f4dbf118d1 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 15 Aug 2023 16:21:20 +0100 Subject: [PATCH 2/4] give me more information --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a659ca9feb99..0b88e85ba11a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -95,7 +95,7 @@ jobs: cache: pip cache-dependency-path: requirements-tests.txt - run: pip install -r requirements-tests.txt - - run: python ./tests/mypy_test.py --platform=${{ matrix.platform }} --python-version=${{ matrix.python-version }} + - run: python ./tests/mypy_test.py --platform=${{ matrix.platform }} --python-version=${{ matrix.python-version }} --verbose # Run mypy slightly differently on the py312 stubs, # as mypyc doesn't work on Python 3.12 yet From 7fb086c050c71b3bf82ed50bbd655879594acd2f Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Thu, 21 Sep 2023 11:44:49 +0200 Subject: [PATCH 3/4] Revert "give me more information" This reverts commit 3deed403f2f09f6f2739e8708513c9f4dbf118d1. --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index cfcd6831194c..c86922bce00c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -95,7 +95,7 @@ jobs: cache: pip cache-dependency-path: requirements-tests.txt - run: pip install -r requirements-tests.txt - - run: python ./tests/mypy_test.py --platform=${{ matrix.platform }} --python-version=${{ matrix.python-version }} --verbose + - run: python ./tests/mypy_test.py --platform=${{ matrix.platform }} --python-version=${{ matrix.python-version }} # Run mypy slightly differently on the py312 stubs, # as at least one non-types dependency (greenlet) can't be installed on Python 3.12 yet From cffeff7666a8ae10ee0424cc5f3e2c4f28238c3d Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Thu, 21 Sep 2023 11:51:05 +0200 Subject: [PATCH 4/4] Rename two files --- stubs/jsonschema/jsonschema/{_validators.pyi => _keywords.pyi} | 0 .../jsonschema/{_legacy_validators.pyi => _legacy_keywords.pyi} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename stubs/jsonschema/jsonschema/{_validators.pyi => _keywords.pyi} (100%) rename stubs/jsonschema/jsonschema/{_legacy_validators.pyi => _legacy_keywords.pyi} (100%) diff --git a/stubs/jsonschema/jsonschema/_validators.pyi b/stubs/jsonschema/jsonschema/_keywords.pyi similarity index 100% rename from stubs/jsonschema/jsonschema/_validators.pyi rename to stubs/jsonschema/jsonschema/_keywords.pyi diff --git a/stubs/jsonschema/jsonschema/_legacy_validators.pyi b/stubs/jsonschema/jsonschema/_legacy_keywords.pyi similarity index 100% rename from stubs/jsonschema/jsonschema/_legacy_validators.pyi rename to stubs/jsonschema/jsonschema/_legacy_keywords.pyi