From 22a09a1ad4c29db805d72287c2249e74380618a8 Mon Sep 17 00:00:00 2001 From: "Michael A. Smith" Date: Fri, 3 Dec 2021 14:04:53 -0500 Subject: [PATCH 01/14] Updated Stubs for jsonschema This PR updates stubs to recognize new attributes added since the original stubbing in #5784. --- stubs/jsonschema/jsonschema/__init__.pyi | 4 +++ stubs/jsonschema/jsonschema/__main__.pyi | 1 + stubs/jsonschema/jsonschema/_format.pyi | 8 +++-- .../jsonschema/_legacy_validators.pyi | 7 +++++ stubs/jsonschema/jsonschema/_types.pyi | 8 ++--- stubs/jsonschema/jsonschema/_utils.pyi | 9 +++--- stubs/jsonschema/jsonschema/_validators.pyi | 19 +++++++++++- stubs/jsonschema/jsonschema/cli.pyi | 29 +++++++++++++++++-- stubs/jsonschema/jsonschema/exceptions.pyi | 14 ++------- stubs/jsonschema/jsonschema/validators.pyi | 24 ++++++--------- 10 files changed, 81 insertions(+), 42 deletions(-) create mode 100644 stubs/jsonschema/jsonschema/__main__.pyi diff --git a/stubs/jsonschema/jsonschema/__init__.pyi b/stubs/jsonschema/jsonschema/__init__.pyi index 87b8e96f56b7..58f30e62cb89 100644 --- a/stubs/jsonschema/jsonschema/__init__.pyi +++ b/stubs/jsonschema/jsonschema/__init__.pyi @@ -1,5 +1,7 @@ from jsonschema._format import ( FormatChecker as FormatChecker, + draft201909_format_checker as draft201909_format_checker, + draft202012_format_checker as draft202012_format_checker, draft3_format_checker as draft3_format_checker, draft4_format_checker as draft4_format_checker, draft6_format_checker as draft6_format_checker, @@ -14,6 +16,8 @@ from jsonschema.exceptions import ( ValidationError as ValidationError, ) from jsonschema.validators import ( + Draft201909Validator as Draft201909Validator, + Draft202012Validator as Draft202012Validator, Draft3Validator as Draft3Validator, Draft4Validator as Draft4Validator, Draft6Validator as Draft6Validator, diff --git a/stubs/jsonschema/jsonschema/__main__.pyi b/stubs/jsonschema/jsonschema/__main__.pyi new file mode 100644 index 000000000000..0da9088b3f43 --- /dev/null +++ b/stubs/jsonschema/jsonschema/__main__.pyi @@ -0,0 +1 @@ +from jsonschema.cli import main as main diff --git a/stubs/jsonschema/jsonschema/_format.pyi b/stubs/jsonschema/jsonschema/_format.pyi index fdab126bb1fa..aad6bd3d4707 100644 --- a/stubs/jsonschema/jsonschema/_format.pyi +++ b/stubs/jsonschema/jsonschema/_format.pyi @@ -1,3 +1,4 @@ +from jsonschema.exceptions import FormatError as FormatError from typing import Any class FormatChecker: @@ -12,6 +13,8 @@ draft3_format_checker: Any draft4_format_checker: Any draft6_format_checker: Any draft7_format_checker: Any +draft201909_format_checker: Any +draft202012_format_checker: Any def is_email(instance): ... def is_ipv4(instance): ... @@ -29,7 +32,8 @@ def is_date(instance): ... def is_draft3_time(instance): ... def is_css_color_code(instance): ... def is_css21_color(instance): ... -def is_css3_color(instance): ... def is_json_pointer(instance): ... def is_relative_json_pointer(instance): ... -def is_uri_template(instance, template_validator=...): ... +def is_uri_template(instance): ... +def is_duration(instance): ... +def is_uuid(instance): ... diff --git a/stubs/jsonschema/jsonschema/_legacy_validators.pyi b/stubs/jsonschema/jsonschema/_legacy_validators.pyi index 40e61896d73a..ef3b7ea46072 100644 --- a/stubs/jsonschema/jsonschema/_legacy_validators.pyi +++ b/stubs/jsonschema/jsonschema/_legacy_validators.pyi @@ -1,8 +1,15 @@ +from jsonschema.exceptions import ValidationError as ValidationError + +def ignore_ref_siblings(schema): ... def dependencies_draft3(validator, dependencies, instance, schema) -> None: ... +def dependencies_draft4_draft6_draft7(validator, dependencies, instance, schema) -> None: ... def disallow_draft3(validator, disallow, instance, schema) -> None: ... def extends_draft3(validator, extends, instance, schema) -> None: ... def items_draft3_draft4(validator, items, instance, schema) -> None: ... +def items_draft6_draft7_draft201909(validator, items, instance, schema) -> None: ... def minimum_draft3_draft4(validator, minimum, instance, schema) -> None: ... def maximum_draft3_draft4(validator, maximum, instance, schema) -> None: ... def properties_draft3(validator, properties, instance, schema) -> None: ... def type_draft3(validator, types, instance, schema) -> None: ... +def contains_draft6_draft7(validator, contains, instance, schema) -> None: ... +def recursiveRef(validator, recursiveRef, instance, schema) -> None: ... diff --git a/stubs/jsonschema/jsonschema/_types.pyi b/stubs/jsonschema/jsonschema/_types.pyi index efbe6ba4e56d..71b578130984 100644 --- a/stubs/jsonschema/jsonschema/_types.pyi +++ b/stubs/jsonschema/jsonschema/_types.pyi @@ -1,3 +1,4 @@ +from jsonschema.exceptions import UndefinedTypeCheck as UndefinedTypeCheck from typing import Any def is_array(checker, instance): ... @@ -14,13 +15,10 @@ class TypeChecker: def redefine(self, type, fn): ... def redefine_many(self, definitions=...): ... def remove(self, *types): ... - def __init__(self, type_checkers=...) -> None: ... - def __lt__(self, other): ... - def __le__(self, other): ... - def __gt__(self, other): ... - def __ge__(self, other): ... draft3_type_checker: Any draft4_type_checker: Any draft6_type_checker: Any draft7_type_checker: Any +draft201909_type_checker: Any +draft202012_type_checker: Any diff --git a/stubs/jsonschema/jsonschema/_utils.pyi b/stubs/jsonschema/jsonschema/_utils.pyi index 596ec6472f06..6f99688c67bb 100644 --- a/stubs/jsonschema/jsonschema/_utils.pyi +++ b/stubs/jsonschema/jsonschema/_utils.pyi @@ -1,6 +1,6 @@ from typing import Any, MutableMapping -class URIDict(MutableMapping[Any, Any]): +class URIDict(MutableMapping): def normalize(self, uri): ... store: Any def __init__(self, *args, **kwargs) -> None: ... @@ -13,13 +13,12 @@ class URIDict(MutableMapping[Any, Any]): class Unset: ... def load_schema(name): ... -def indent(string, times: int = ...): ... -def format_as_index(indices): ... +def format_as_index(container, indices): ... def find_additional_properties(instance, schema) -> None: ... def extras_msg(extras): ... -def types_msg(instance, types): ... -def flatten(suitable_for_isinstance): ... def ensure_list(thing): ... def equal(one, two): ... def unbool(element, true=..., false=...): ... def uniq(container): ... +def find_evaluated_item_indexes_by_schema(validator, instance, schema): ... +def find_evaluated_property_keys_by_schema(validator, instance, schema): ... diff --git a/stubs/jsonschema/jsonschema/_validators.pyi b/stubs/jsonschema/jsonschema/_validators.pyi index 8afcc3c07b4c..31a8ae365668 100644 --- a/stubs/jsonschema/jsonschema/_validators.pyi +++ b/stubs/jsonschema/jsonschema/_validators.pyi @@ -1,3 +1,15 @@ +from jsonschema._utils import ( + ensure_list as ensure_list, + equal as equal, + extras_msg as extras_msg, + find_additional_properties as find_additional_properties, + find_evaluated_item_indexes_by_schema as find_evaluated_item_indexes_by_schema, + find_evaluated_property_keys_by_schema as find_evaluated_property_keys_by_schema, + unbool as unbool, + uniq as uniq, +) +from jsonschema.exceptions import FormatError as FormatError, ValidationError as ValidationError + def patternProperties(validator, patternProperties, instance, schema) -> None: ... def propertyNames(validator, propertyNames, instance, schema) -> None: ... def additionalProperties(validator, aP, instance, schema) -> None: ... @@ -17,9 +29,11 @@ def pattern(validator, patrn, instance, schema) -> None: ... def format(validator, format, instance, schema) -> None: ... def minLength(validator, mL, instance, schema) -> None: ... def maxLength(validator, mL, instance, schema) -> None: ... -def dependencies(validator, dependencies, instance, schema) -> None: ... +def dependentRequired(validator, dependentRequired, instance, schema) -> None: ... +def dependentSchemas(validator, dependentSchemas, instance, schema) -> None: ... def enum(validator, enums, instance, schema) -> None: ... def ref(validator, ref, instance, schema) -> None: ... +def dynamicRef(validator, dynamicRef, instance, schema) -> None: ... def type(validator, types, instance, schema) -> None: ... def properties(validator, properties, instance, schema) -> None: ... def required(validator, required, instance, schema) -> None: ... @@ -30,3 +44,6 @@ def anyOf(validator, anyOf, instance, schema) -> None: ... def oneOf(validator, oneOf, instance, schema) -> None: ... def not_(validator, not_schema, instance, schema) -> None: ... def if_(validator, if_schema, instance, schema) -> None: ... +def unevaluatedItems(validator, unevaluatedItems, instance, schema) -> None: ... +def unevaluatedProperties(validator, unevaluatedProperties, instance, schema) -> None: ... +def prefixItems(validator, prefixItems, instance, schema) -> None: ... diff --git a/stubs/jsonschema/jsonschema/cli.pyi b/stubs/jsonschema/jsonschema/cli.pyi index 1ccff3f60407..6e71c8628da5 100644 --- a/stubs/jsonschema/jsonschema/cli.pyi +++ b/stubs/jsonschema/jsonschema/cli.pyi @@ -1,10 +1,33 @@ +from jsonschema._reflect import namedAny as namedAny +from jsonschema.exceptions import SchemaError as SchemaError +from jsonschema.validators import RefResolver as RefResolver, validator_for as validator_for from typing import Any -from jsonschema._reflect import namedAny as namedAny -from jsonschema.validators import validator_for as validator_for +class _CannotLoadFile(Exception): ... + +class _Outputter: + @classmethod + def from_arguments(cls, arguments, stdout, stderr): ... + def load(self, path): ... + def filenotfound_error(self, **kwargs) -> None: ... + def parsing_error(self, **kwargs) -> None: ... + def validation_error(self, **kwargs) -> None: ... + def validation_success(self, **kwargs) -> None: ... + +class _PrettyFormatter: + def filenotfound_error(self, path, exc_info): ... + def parsing_error(self, path, exc_info): ... + def validation_error(self, instance_path, error): ... + def validation_success(self, instance_path): ... + +class _PlainFormatter: + def filenotfound_error(self, path, exc_info): ... + def parsing_error(self, path, exc_info): ... + def validation_error(self, instance_path, error): ... + def validation_success(self, instance_path): ... parser: Any def parse_args(args): ... def main(args=...) -> None: ... -def run(arguments, stdout=..., stderr=...): ... +def run(arguments, stdout=..., stderr=..., stdin=...): ... diff --git a/stubs/jsonschema/jsonschema/exceptions.pyi b/stubs/jsonschema/jsonschema/exceptions.pyi index 078d44b643c2..8110ac7f5f2f 100644 --- a/stubs/jsonschema/jsonschema/exceptions.pyi +++ b/stubs/jsonschema/jsonschema/exceptions.pyi @@ -27,41 +27,33 @@ class _Error(Exception): schema_path=..., parent: Any | None = ..., ) -> None: ... - def __unicode__(self): ... @classmethod def create_from(cls, other): ... @property def absolute_path(self): ... @property def absolute_schema_path(self): ... + @property + def json_path(self): ... class ValidationError(_Error): ... class SchemaError(_Error): ... - -class RefResolutionError(Exception): - def __init__(self, cause) -> None: ... - def __lt__(self, other): ... - def __le__(self, other): ... - def __gt__(self, other): ... - def __ge__(self, other): ... +class RefResolutionError(Exception): ... class UndefinedTypeCheck(Exception): type: Any def __init__(self, type) -> None: ... - def __unicode__(self): ... class UnknownType(Exception): type: Any instance: Any schema: Any def __init__(self, type, instance, schema) -> None: ... - def __unicode__(self): ... class FormatError(Exception): message: Any cause: Any def __init__(self, message, cause: Any | None = ...) -> None: ... - def __unicode__(self): ... class ErrorTree: errors: Any diff --git a/stubs/jsonschema/jsonschema/validators.pyi b/stubs/jsonschema/jsonschema/validators.pyi index b9a078e601f9..d71823d79af4 100644 --- a/stubs/jsonschema/jsonschema/validators.pyi +++ b/stubs/jsonschema/jsonschema/validators.pyi @@ -1,32 +1,26 @@ -from typing import Any - from jsonschema import exceptions as exceptions -from jsonschema.exceptions import ErrorTree as ErrorTree - -class _DontDoThat(Exception): ... - -validators: Any -meta_schemas: Any +from typing import Any +def __getattr__(name): ... def validates(version): ... - -class _DefaultTypesDeprecatingMetaClass(type): - DEFAULT_TYPES: Any - def create( meta_schema, validators=..., version: Any | None = ..., - default_types: Any | None = ..., - type_checker: Any | None = ..., + type_checker=..., id_of=..., + applicable_validators=..., +): ... +def extend( + validator, validators=..., version: Any | None = ..., type_checker: Any | None = ... ): ... -def extend(validator, validators=..., version: Any | None = ..., type_checker: Any | None = ...): ... Draft3Validator: Any Draft4Validator: Any Draft6Validator: Any Draft7Validator: Any +Draft201909Validator: Any +Draft202012Validator: Any class RefResolver: referrer: Any From c0a7944e2e80a9c418f7e2b9f02fc497b1bc1792 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 3 Dec 2021 19:08:15 +0000 Subject: [PATCH 02/14] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stubs/jsonschema/@tests/stubtest_allowlist.txt | 1 - stubs/jsonschema/METADATA.toml | 2 +- stubs/jsonschema/jsonschema/__init__.pyi | 8 ++++---- stubs/jsonschema/jsonschema/_format.pyi | 3 ++- stubs/jsonschema/jsonschema/_types.pyi | 4 +++- stubs/jsonschema/jsonschema/_utils.pyi | 2 +- stubs/jsonschema/jsonschema/cli.pyi | 3 ++- stubs/jsonschema/jsonschema/exceptions.pyi | 4 +++- stubs/jsonschema/jsonschema/validators.pyi | 16 ++++------------ 9 files changed, 20 insertions(+), 23 deletions(-) diff --git a/stubs/jsonschema/@tests/stubtest_allowlist.txt b/stubs/jsonschema/@tests/stubtest_allowlist.txt index 5f66c81014d0..5b1a8081d5e1 100644 --- a/stubs/jsonschema/@tests/stubtest_allowlist.txt +++ b/stubs/jsonschema/@tests/stubtest_allowlist.txt @@ -1,5 +1,4 @@ jsonschema._format.is_css21_color -jsonschema._format.is_css3_color jsonschema._format.is_css_color_code jsonschema._format.is_datetime jsonschema._format.is_idn_host_name diff --git a/stubs/jsonschema/METADATA.toml b/stubs/jsonschema/METADATA.toml index 38c94680a9a8..cb7498d03056 100644 --- a/stubs/jsonschema/METADATA.toml +++ b/stubs/jsonschema/METADATA.toml @@ -1 +1 @@ -version = "3.2.*" +version = "4.2.*" diff --git a/stubs/jsonschema/jsonschema/__init__.pyi b/stubs/jsonschema/jsonschema/__init__.pyi index 58f30e62cb89..96cfcb3ccdf7 100644 --- a/stubs/jsonschema/jsonschema/__init__.pyi +++ b/stubs/jsonschema/jsonschema/__init__.pyi @@ -1,11 +1,11 @@ from jsonschema._format import ( FormatChecker as FormatChecker, - draft201909_format_checker as draft201909_format_checker, - draft202012_format_checker as draft202012_format_checker, draft3_format_checker as draft3_format_checker, draft4_format_checker as draft4_format_checker, draft6_format_checker as draft6_format_checker, draft7_format_checker as draft7_format_checker, + draft201909_format_checker as draft201909_format_checker, + draft202012_format_checker as draft202012_format_checker, ) from jsonschema._types import TypeChecker as TypeChecker from jsonschema.exceptions import ( @@ -16,12 +16,12 @@ from jsonschema.exceptions import ( ValidationError as ValidationError, ) from jsonschema.validators import ( - Draft201909Validator as Draft201909Validator, - Draft202012Validator as Draft202012Validator, Draft3Validator as Draft3Validator, Draft4Validator as Draft4Validator, Draft6Validator as Draft6Validator, Draft7Validator as Draft7Validator, + Draft201909Validator as Draft201909Validator, + Draft202012Validator as Draft202012Validator, RefResolver as RefResolver, validate as validate, ) diff --git a/stubs/jsonschema/jsonschema/_format.pyi b/stubs/jsonschema/jsonschema/_format.pyi index aad6bd3d4707..82767037e151 100644 --- a/stubs/jsonschema/jsonschema/_format.pyi +++ b/stubs/jsonschema/jsonschema/_format.pyi @@ -1,6 +1,7 @@ -from jsonschema.exceptions import FormatError as FormatError from typing import Any +from jsonschema.exceptions import FormatError as FormatError + class FormatChecker: checkers: Any def __init__(self, formats: Any | None = ...) -> None: ... diff --git a/stubs/jsonschema/jsonschema/_types.pyi b/stubs/jsonschema/jsonschema/_types.pyi index 71b578130984..ddb01c9f048a 100644 --- a/stubs/jsonschema/jsonschema/_types.pyi +++ b/stubs/jsonschema/jsonschema/_types.pyi @@ -1,5 +1,6 @@ +from typing import Any, Callable, Mapping + from jsonschema.exceptions import UndefinedTypeCheck as UndefinedTypeCheck -from typing import Any def is_array(checker, instance): ... def is_bool(checker, instance): ... @@ -11,6 +12,7 @@ def is_string(checker, instance): ... def is_any(checker, instance): ... class TypeChecker: + def __init__(self, type_checkers: Any) -> None: ... def is_type(self, instance, type): ... def redefine(self, type, fn): ... def redefine_many(self, definitions=...): ... diff --git a/stubs/jsonschema/jsonschema/_utils.pyi b/stubs/jsonschema/jsonschema/_utils.pyi index 6f99688c67bb..d93aca75aad9 100644 --- a/stubs/jsonschema/jsonschema/_utils.pyi +++ b/stubs/jsonschema/jsonschema/_utils.pyi @@ -1,6 +1,6 @@ from typing import Any, MutableMapping -class URIDict(MutableMapping): +class URIDict(MutableMapping[Any, Any]): def normalize(self, uri): ... store: Any def __init__(self, *args, **kwargs) -> None: ... diff --git a/stubs/jsonschema/jsonschema/cli.pyi b/stubs/jsonschema/jsonschema/cli.pyi index 6e71c8628da5..4a4edc066ffb 100644 --- a/stubs/jsonschema/jsonschema/cli.pyi +++ b/stubs/jsonschema/jsonschema/cli.pyi @@ -1,7 +1,8 @@ +from typing import Any + from jsonschema._reflect import namedAny as namedAny from jsonschema.exceptions import SchemaError as SchemaError from jsonschema.validators import RefResolver as RefResolver, validator_for as validator_for -from typing import Any class _CannotLoadFile(Exception): ... diff --git a/stubs/jsonschema/jsonschema/exceptions.pyi b/stubs/jsonschema/jsonschema/exceptions.pyi index 8110ac7f5f2f..466264dbbf0c 100644 --- a/stubs/jsonschema/jsonschema/exceptions.pyi +++ b/stubs/jsonschema/jsonschema/exceptions.pyi @@ -38,7 +38,9 @@ class _Error(Exception): class ValidationError(_Error): ... class SchemaError(_Error): ... -class RefResolutionError(Exception): ... + +class RefResolutionError(Exception): + def __init__(self, cause: str) -> None: ... class UndefinedTypeCheck(Exception): type: Any diff --git a/stubs/jsonschema/jsonschema/validators.pyi b/stubs/jsonschema/jsonschema/validators.pyi index d71823d79af4..baaa2d18a4dc 100644 --- a/stubs/jsonschema/jsonschema/validators.pyi +++ b/stubs/jsonschema/jsonschema/validators.pyi @@ -1,19 +1,11 @@ -from jsonschema import exceptions as exceptions from typing import Any +from jsonschema import exceptions as exceptions + def __getattr__(name): ... def validates(version): ... -def create( - meta_schema, - validators=..., - version: Any | None = ..., - type_checker=..., - id_of=..., - applicable_validators=..., -): ... -def extend( - validator, validators=..., version: Any | None = ..., type_checker: Any | None = ... -): ... +def create(meta_schema, validators=..., version: Any | None = ..., type_checker=..., id_of=..., applicable_validators=...): ... +def extend(validator, validators=..., version: Any | None = ..., type_checker: Any | None = ...): ... Draft3Validator: Any Draft4Validator: Any From 1f82fcb3d7a29a4c2bb36473f86b02c4c2aef7d6 Mon Sep 17 00:00:00 2001 From: "Michael A. Smith" Date: Fri, 3 Dec 2021 16:03:58 -0500 Subject: [PATCH 03/14] Update stubs/jsonschema/jsonschema/_types.pyi Co-authored-by: Sebastian Rittau --- stubs/jsonschema/jsonschema/_types.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/jsonschema/jsonschema/_types.pyi b/stubs/jsonschema/jsonschema/_types.pyi index ddb01c9f048a..de51762342b2 100644 --- a/stubs/jsonschema/jsonschema/_types.pyi +++ b/stubs/jsonschema/jsonschema/_types.pyi @@ -12,7 +12,7 @@ def is_string(checker, instance): ... def is_any(checker, instance): ... class TypeChecker: - def __init__(self, type_checkers: Any) -> None: ... + def __init__(self, type_checkers: Mapping[str, Callable[[object], bool]] = ...) -> None: ... def is_type(self, instance, type): ... def redefine(self, type, fn): ... def redefine_many(self, definitions=...): ... From 979a7c90fcdac25ac2f85ba0d40cbad999dedbbb Mon Sep 17 00:00:00 2001 From: "Michael A. Smith" Date: Sat, 4 Dec 2021 20:53:31 -0500 Subject: [PATCH 04/14] Delete __main__.pyi --- stubs/jsonschema/jsonschema/__main__.pyi | 1 - 1 file changed, 1 deletion(-) delete mode 100644 stubs/jsonschema/jsonschema/__main__.pyi diff --git a/stubs/jsonschema/jsonschema/__main__.pyi b/stubs/jsonschema/jsonschema/__main__.pyi deleted file mode 100644 index 0da9088b3f43..000000000000 --- a/stubs/jsonschema/jsonschema/__main__.pyi +++ /dev/null @@ -1 +0,0 @@ -from jsonschema.cli import main as main From 701ddf0ee33d4273be56b9df93f208c9b2e8ea10 Mon Sep 17 00:00:00 2001 From: "Michael A. Smith" Date: Sat, 4 Dec 2021 21:08:29 -0500 Subject: [PATCH 05/14] Delete compat.pyi --- stubs/jsonschema/jsonschema/compat.pyi | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 stubs/jsonschema/jsonschema/compat.pyi diff --git a/stubs/jsonschema/jsonschema/compat.pyi b/stubs/jsonschema/jsonschema/compat.pyi deleted file mode 100644 index e69de29bb2d1..000000000000 From 45d06a46c012014c2d696509e3c6d4bf96a43bb4 Mon Sep 17 00:00:00 2001 From: "Michael A. Smith" Date: Sat, 4 Dec 2021 21:20:53 -0500 Subject: [PATCH 06/14] Update cli.pyi --- stubs/jsonschema/jsonschema/cli.pyi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stubs/jsonschema/jsonschema/cli.pyi b/stubs/jsonschema/jsonschema/cli.pyi index 4a4edc066ffb..db820d22deff 100644 --- a/stubs/jsonschema/jsonschema/cli.pyi +++ b/stubs/jsonschema/jsonschema/cli.pyi @@ -7,6 +7,7 @@ from jsonschema.validators import RefResolver as RefResolver, validator_for as v class _CannotLoadFile(Exception): ... class _Outputter: + def __init__(self, formatter, stdout, stderr): ... @classmethod def from_arguments(cls, arguments, stdout, stderr): ... def load(self, path): ... @@ -22,6 +23,7 @@ class _PrettyFormatter: def validation_success(self, instance_path): ... class _PlainFormatter: + def __init__(self, error_format): ... def filenotfound_error(self, path, exc_info): ... def parsing_error(self, path, exc_info): ... def validation_error(self, instance_path, error): ... From 3c21aaf9a3a9587e2e8c46f5c3924bfacab81f0e Mon Sep 17 00:00:00 2001 From: "Michael A. Smith" Date: Sat, 4 Dec 2021 21:29:52 -0500 Subject: [PATCH 07/14] Update _format.pyi --- stubs/jsonschema/jsonschema/_format.pyi | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stubs/jsonschema/jsonschema/_format.pyi b/stubs/jsonschema/jsonschema/_format.pyi index 82767037e151..1c94f1bafbdd 100644 --- a/stubs/jsonschema/jsonschema/_format.pyi +++ b/stubs/jsonschema/jsonschema/_format.pyi @@ -20,7 +20,8 @@ draft202012_format_checker: Any def is_email(instance): ... def is_ipv4(instance): ... def is_ipv6(instance): ... -def is_host_name(instance): ... +# is_host_name is only defined if fqdn is installed. +# def is_host_name(instance): ... def is_idn_host_name(instance): ... def is_uri(instance): ... def is_uri_reference(instance): ... @@ -36,5 +37,6 @@ def is_css21_color(instance): ... def is_json_pointer(instance): ... def is_relative_json_pointer(instance): ... def is_uri_template(instance): ... -def is_duration(instance): ... +# is_duration is only defined if isoduration is installed. +# def is_duration(instance): ... def is_uuid(instance): ... From 27b8f09fac9501e1fcc99879900a7669bf46cd40 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 5 Dec 2021 02:30:54 +0000 Subject: [PATCH 08/14] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stubs/jsonschema/jsonschema/_format.pyi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stubs/jsonschema/jsonschema/_format.pyi b/stubs/jsonschema/jsonschema/_format.pyi index 1c94f1bafbdd..8b3031d6f02e 100644 --- a/stubs/jsonschema/jsonschema/_format.pyi +++ b/stubs/jsonschema/jsonschema/_format.pyi @@ -20,6 +20,7 @@ draft202012_format_checker: Any def is_email(instance): ... def is_ipv4(instance): ... def is_ipv6(instance): ... + # is_host_name is only defined if fqdn is installed. # def is_host_name(instance): ... def is_idn_host_name(instance): ... @@ -37,6 +38,7 @@ def is_css21_color(instance): ... def is_json_pointer(instance): ... def is_relative_json_pointer(instance): ... def is_uri_template(instance): ... + # is_duration is only defined if isoduration is installed. # def is_duration(instance): ... def is_uuid(instance): ... From affc7d12a806682bc2e1f6c9eb11f9d4ba1681df Mon Sep 17 00:00:00 2001 From: "Michael A. Smith" Date: Sun, 5 Dec 2021 14:25:33 -0500 Subject: [PATCH 09/14] Update validators.pyi --- stubs/jsonschema/jsonschema/validators.pyi | 1 - 1 file changed, 1 deletion(-) diff --git a/stubs/jsonschema/jsonschema/validators.pyi b/stubs/jsonschema/jsonschema/validators.pyi index baaa2d18a4dc..7b54c6b4ee76 100644 --- a/stubs/jsonschema/jsonschema/validators.pyi +++ b/stubs/jsonschema/jsonschema/validators.pyi @@ -2,7 +2,6 @@ from typing import Any from jsonschema import exceptions as exceptions -def __getattr__(name): ... def validates(version): ... def create(meta_schema, validators=..., version: Any | None = ..., type_checker=..., id_of=..., applicable_validators=...): ... def extend(validator, validators=..., version: Any | None = ..., type_checker: Any | None = ...): ... From 1e52a7848954866537076118b5d4cadb7f0d3353 Mon Sep 17 00:00:00 2001 From: "Michael A. Smith" Date: Sun, 5 Dec 2021 16:52:27 -0500 Subject: [PATCH 10/14] Remove Redundant Imports --- stubs/jsonschema/jsonschema/_format.pyi | 2 -- stubs/jsonschema/jsonschema/_legacy_validators.pyi | 2 -- stubs/jsonschema/jsonschema/_types.pyi | 2 -- stubs/jsonschema/jsonschema/_validators.pyi | 12 ------------ stubs/jsonschema/jsonschema/cli.pyi | 4 ---- stubs/jsonschema/jsonschema/validators.pyi | 2 -- 6 files changed, 24 deletions(-) diff --git a/stubs/jsonschema/jsonschema/_format.pyi b/stubs/jsonschema/jsonschema/_format.pyi index 8b3031d6f02e..9fa70d7574f1 100644 --- a/stubs/jsonschema/jsonschema/_format.pyi +++ b/stubs/jsonschema/jsonschema/_format.pyi @@ -1,7 +1,5 @@ from typing import Any -from jsonschema.exceptions import FormatError as FormatError - class FormatChecker: checkers: Any def __init__(self, formats: Any | None = ...) -> None: ... diff --git a/stubs/jsonschema/jsonschema/_legacy_validators.pyi b/stubs/jsonschema/jsonschema/_legacy_validators.pyi index ef3b7ea46072..51ed915fac45 100644 --- a/stubs/jsonschema/jsonschema/_legacy_validators.pyi +++ b/stubs/jsonschema/jsonschema/_legacy_validators.pyi @@ -1,5 +1,3 @@ -from jsonschema.exceptions import ValidationError as ValidationError - def ignore_ref_siblings(schema): ... def dependencies_draft3(validator, dependencies, instance, schema) -> None: ... def dependencies_draft4_draft6_draft7(validator, dependencies, instance, schema) -> None: ... diff --git a/stubs/jsonschema/jsonschema/_types.pyi b/stubs/jsonschema/jsonschema/_types.pyi index de51762342b2..5d7c56c999ee 100644 --- a/stubs/jsonschema/jsonschema/_types.pyi +++ b/stubs/jsonschema/jsonschema/_types.pyi @@ -1,7 +1,5 @@ from typing import Any, Callable, Mapping -from jsonschema.exceptions import UndefinedTypeCheck as UndefinedTypeCheck - def is_array(checker, instance): ... def is_bool(checker, instance): ... def is_integer(checker, instance): ... diff --git a/stubs/jsonschema/jsonschema/_validators.pyi b/stubs/jsonschema/jsonschema/_validators.pyi index 31a8ae365668..f6daf12685ea 100644 --- a/stubs/jsonschema/jsonschema/_validators.pyi +++ b/stubs/jsonschema/jsonschema/_validators.pyi @@ -1,15 +1,3 @@ -from jsonschema._utils import ( - ensure_list as ensure_list, - equal as equal, - extras_msg as extras_msg, - find_additional_properties as find_additional_properties, - find_evaluated_item_indexes_by_schema as find_evaluated_item_indexes_by_schema, - find_evaluated_property_keys_by_schema as find_evaluated_property_keys_by_schema, - unbool as unbool, - uniq as uniq, -) -from jsonschema.exceptions import FormatError as FormatError, ValidationError as ValidationError - def patternProperties(validator, patternProperties, instance, schema) -> None: ... def propertyNames(validator, propertyNames, instance, schema) -> None: ... def additionalProperties(validator, aP, instance, schema) -> None: ... diff --git a/stubs/jsonschema/jsonschema/cli.pyi b/stubs/jsonschema/jsonschema/cli.pyi index db820d22deff..85c3bd71d0a2 100644 --- a/stubs/jsonschema/jsonschema/cli.pyi +++ b/stubs/jsonschema/jsonschema/cli.pyi @@ -1,9 +1,5 @@ from typing import Any -from jsonschema._reflect import namedAny as namedAny -from jsonschema.exceptions import SchemaError as SchemaError -from jsonschema.validators import RefResolver as RefResolver, validator_for as validator_for - class _CannotLoadFile(Exception): ... class _Outputter: diff --git a/stubs/jsonschema/jsonschema/validators.pyi b/stubs/jsonschema/jsonschema/validators.pyi index 7b54c6b4ee76..a5d98977d32d 100644 --- a/stubs/jsonschema/jsonschema/validators.pyi +++ b/stubs/jsonschema/jsonschema/validators.pyi @@ -1,7 +1,5 @@ from typing import Any -from jsonschema import exceptions as exceptions - def validates(version): ... def create(meta_schema, validators=..., version: Any | None = ..., type_checker=..., id_of=..., applicable_validators=...): ... def extend(validator, validators=..., version: Any | None = ..., type_checker: Any | None = ...): ... From 5d99acc0a28b5b636c5f64e949ee0f4fb507f813 Mon Sep 17 00:00:00 2001 From: "Michael A. Smith" Date: Sun, 5 Dec 2021 18:00:31 -0500 Subject: [PATCH 11/14] Update _format.pyi --- stubs/jsonschema/jsonschema/_format.pyi | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/stubs/jsonschema/jsonschema/_format.pyi b/stubs/jsonschema/jsonschema/_format.pyi index 9fa70d7574f1..8e8a6b28c1b3 100644 --- a/stubs/jsonschema/jsonschema/_format.pyi +++ b/stubs/jsonschema/jsonschema/_format.pyi @@ -8,12 +8,12 @@ class FormatChecker: def check(self, instance, format) -> None: ... def conforms(self, instance, format): ... -draft3_format_checker: Any -draft4_format_checker: Any -draft6_format_checker: Any -draft7_format_checker: Any -draft201909_format_checker: Any -draft202012_format_checker: Any +draft3_format_checker: FormatChecker +draft4_format_checker: FormatChecker +draft6_format_checker: FormatChecker +draft7_format_checker: FormatChecker +draft201909_format_checker: FormatChecker +draft202012_format_checker: FormatChecker def is_email(instance): ... def is_ipv4(instance): ... From 50b96cc257b072b302aa246511808a57de4aee5d Mon Sep 17 00:00:00 2001 From: "Michael A. Smith" Date: Mon, 6 Dec 2021 10:26:18 -0500 Subject: [PATCH 12/14] Add Back Optional Validators and Refine Types --- .../jsonschema/@tests/stubtest_allowlist.txt | 2 + stubs/jsonschema/jsonschema/_format.pyi | 48 +++++++++---------- .../jsonschema/_legacy_validators.pyi | 4 +- stubs/jsonschema/jsonschema/_types.pyi | 38 +++++++-------- stubs/jsonschema/jsonschema/_utils.pyi | 22 ++++----- stubs/jsonschema/jsonschema/validators.pyi | 4 +- 6 files changed, 61 insertions(+), 57 deletions(-) diff --git a/stubs/jsonschema/@tests/stubtest_allowlist.txt b/stubs/jsonschema/@tests/stubtest_allowlist.txt index 5b1a8081d5e1..48d08e94735c 100644 --- a/stubs/jsonschema/@tests/stubtest_allowlist.txt +++ b/stubs/jsonschema/@tests/stubtest_allowlist.txt @@ -1,6 +1,8 @@ jsonschema._format.is_css21_color jsonschema._format.is_css_color_code jsonschema._format.is_datetime +jsonschema._format.is_duration +jsonschema._format.is_host_name jsonschema._format.is_idn_host_name jsonschema._format.is_iri jsonschema._format.is_iri_reference diff --git a/stubs/jsonschema/jsonschema/_format.pyi b/stubs/jsonschema/jsonschema/_format.pyi index 8e8a6b28c1b3..0c81937de44f 100644 --- a/stubs/jsonschema/jsonschema/_format.pyi +++ b/stubs/jsonschema/jsonschema/_format.pyi @@ -1,12 +1,12 @@ -from typing import Any +from typing import Any, Iterable class FormatChecker: checkers: Any - def __init__(self, formats: Any | None = ...) -> None: ... + def __init__(self, formats: Iterable[Any] | None = ...) -> None: ... def checks(self, format, raises=...): ... cls_checks: Any def check(self, instance, format) -> None: ... - def conforms(self, instance, format): ... + def conforms(self, instance, format) -> bool: ... draft3_format_checker: FormatChecker draft4_format_checker: FormatChecker @@ -15,28 +15,28 @@ draft7_format_checker: FormatChecker draft201909_format_checker: FormatChecker draft202012_format_checker: FormatChecker -def is_email(instance): ... -def is_ipv4(instance): ... -def is_ipv6(instance): ... +def is_email(instance) -> bool: ... +def is_ipv4(instance) -> bool: ... +def is_ipv6(instance) -> bool: ... # is_host_name is only defined if fqdn is installed. -# def is_host_name(instance): ... -def is_idn_host_name(instance): ... -def is_uri(instance): ... -def is_uri_reference(instance): ... -def is_iri(instance): ... -def is_iri_reference(instance): ... -def is_datetime(instance): ... -def is_time(instance): ... -def is_regex(instance): ... -def is_date(instance): ... -def is_draft3_time(instance): ... -def is_css_color_code(instance): ... -def is_css21_color(instance): ... -def is_json_pointer(instance): ... -def is_relative_json_pointer(instance): ... -def is_uri_template(instance): ... +def is_host_name(instance) -> bool: ... +def is_idn_host_name(instance) -> bool: ... +def is_uri(instance) -> bool: ... +def is_uri_reference(instance) -> bool: ... +def is_iri(instance) -> bool: ... +def is_iri_reference(instance) -> bool: ... +def is_datetime(instance) -> bool: ... +def is_time(instance) -> bool: ... +def is_regex(instance) -> bool: ... +def is_date(instance) -> bool: ... +def is_draft3_time(instance) -> bool: ... +def is_css_color_code(instance) -> bool: ... +def is_css21_color(instance) -> bool: ... +def is_json_pointer(instance) -> bool: ... +def is_relative_json_pointer(instance) -> bool: ... +def is_uri_template(instance) -> bool: ... # is_duration is only defined if isoduration is installed. -# def is_duration(instance): ... -def is_uuid(instance): ... +def is_duration(instance) -> bool: ... +def is_uuid(instance) -> bool: ... diff --git a/stubs/jsonschema/jsonschema/_legacy_validators.pyi b/stubs/jsonschema/jsonschema/_legacy_validators.pyi index 51ed915fac45..08a7dd5394ea 100644 --- a/stubs/jsonschema/jsonschema/_legacy_validators.pyi +++ b/stubs/jsonschema/jsonschema/_legacy_validators.pyi @@ -1,4 +1,6 @@ -def ignore_ref_siblings(schema): ... +from typing import Any, ItemsView + +def ignore_ref_siblings(schema) -> list[tuple[str, Any]] | ItemsView[str, Any]: ... def dependencies_draft3(validator, dependencies, instance, schema) -> None: ... def dependencies_draft4_draft6_draft7(validator, dependencies, instance, schema) -> None: ... def disallow_draft3(validator, disallow, instance, schema) -> None: ... diff --git a/stubs/jsonschema/jsonschema/_types.pyi b/stubs/jsonschema/jsonschema/_types.pyi index 5d7c56c999ee..cb8afaad0ee6 100644 --- a/stubs/jsonschema/jsonschema/_types.pyi +++ b/stubs/jsonschema/jsonschema/_types.pyi @@ -1,24 +1,24 @@ -from typing import Any, Callable, Mapping +from typing import Any, Callable, Iterable, Mapping -def is_array(checker, instance): ... -def is_bool(checker, instance): ... -def is_integer(checker, instance): ... -def is_null(checker, instance): ... -def is_number(checker, instance): ... -def is_object(checker, instance): ... -def is_string(checker, instance): ... -def is_any(checker, instance): ... +def is_array(checker, instance) -> bool: ... +def is_bool(checker, instance) -> bool: ... +def is_integer(checker, instance) -> bool: ... +def is_null(checker, instance) -> bool: ... +def is_number(checker, instance) -> bool: ... +def is_object(checker, instance) -> bool: ... +def is_string(checker, instance) -> bool: ... +def is_any(checker, instance) -> bool: ... class TypeChecker: def __init__(self, type_checkers: Mapping[str, Callable[[object], bool]] = ...) -> None: ... - def is_type(self, instance, type): ... - def redefine(self, type, fn): ... - def redefine_many(self, definitions=...): ... - def remove(self, *types): ... + def is_type(self, instance, type: str) -> bool: ... + def redefine(self, type: str, fn: Callable[..., Any]) -> TypeChecker: ... + def redefine_many(self, definitions=...) -> TypeChecker: ... + def remove(self, *types: Iterable[str]) -> TypeChecker: ... -draft3_type_checker: Any -draft4_type_checker: Any -draft6_type_checker: Any -draft7_type_checker: Any -draft201909_type_checker: Any -draft202012_type_checker: Any +draft3_type_checker: TypeChecker +draft4_type_checker: TypeChecker +draft6_type_checker: TypeChecker +draft7_type_checker: TypeChecker +draft201909_type_checker: TypeChecker +draft202012_type_checker: TypeChecker diff --git a/stubs/jsonschema/jsonschema/_utils.pyi b/stubs/jsonschema/jsonschema/_utils.pyi index d93aca75aad9..28b6ac1dea87 100644 --- a/stubs/jsonschema/jsonschema/_utils.pyi +++ b/stubs/jsonschema/jsonschema/_utils.pyi @@ -1,8 +1,8 @@ -from typing import Any, MutableMapping +from typing import Any, Generator, Iterable, Mapping, MutableMapping, Sized class URIDict(MutableMapping[Any, Any]): - def normalize(self, uri): ... - store: Any + 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: ... @@ -13,12 +13,12 @@ class URIDict(MutableMapping[Any, Any]): class Unset: ... def load_schema(name): ... -def format_as_index(container, indices): ... -def find_additional_properties(instance, schema) -> None: ... -def extras_msg(extras): ... -def ensure_list(thing): ... -def equal(one, two): ... +def format_as_index(container: str, indices) -> str: ... +def find_additional_properties(instance: Iterable[Any], schema: Mapping[Any, Any]) -> Generator[Any, None, None]: ... +def extras_msg(extras: Iterable[Any] | Sized) -> str: ... +def ensure_list(thing) -> list: ... +def equal(one, two) -> bool: ... def unbool(element, true=..., false=...): ... -def uniq(container): ... -def find_evaluated_item_indexes_by_schema(validator, instance, schema): ... -def find_evaluated_property_keys_by_schema(validator, instance, schema): ... +def uniq(container) -> bool: ... +def find_evaluated_item_indexes_by_schema(validator, instance, schema) -> list: ... +def find_evaluated_property_keys_by_schema(validator, instance, schema) -> list: ... diff --git a/stubs/jsonschema/jsonschema/validators.pyi b/stubs/jsonschema/jsonschema/validators.pyi index a5d98977d32d..7829021784ac 100644 --- a/stubs/jsonschema/jsonschema/validators.pyi +++ b/stubs/jsonschema/jsonschema/validators.pyi @@ -1,6 +1,6 @@ -from typing import Any +from typing import Any, Callable -def validates(version): ... +def validates(version: str) -> Callable[..., Any]: ... def create(meta_schema, validators=..., version: Any | None = ..., type_checker=..., id_of=..., applicable_validators=...): ... def extend(validator, validators=..., version: Any | None = ..., type_checker: Any | None = ...): ... From 539ce832efb33df7dc64afa1f8f63d843914dc45 Mon Sep 17 00:00:00 2001 From: "Michael A. Smith" Date: Mon, 6 Dec 2021 10:56:44 -0500 Subject: [PATCH 13/14] Further Refinements As recommended by @Akuli --- stubs/jsonschema/jsonschema/_format.pyi | 2 +- stubs/jsonschema/jsonschema/_types.pyi | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/stubs/jsonschema/jsonschema/_format.pyi b/stubs/jsonschema/jsonschema/_format.pyi index 0c81937de44f..492800ab5190 100644 --- a/stubs/jsonschema/jsonschema/_format.pyi +++ b/stubs/jsonschema/jsonschema/_format.pyi @@ -2,7 +2,7 @@ from typing import Any, Iterable class FormatChecker: checkers: Any - def __init__(self, formats: Iterable[Any] | None = ...) -> None: ... + def __init__(self, formats: Iterable[str] | None = ...) -> None: ... def checks(self, format, raises=...): ... cls_checks: Any def check(self, instance, format) -> None: ... diff --git a/stubs/jsonschema/jsonschema/_types.pyi b/stubs/jsonschema/jsonschema/_types.pyi index cb8afaad0ee6..5c97055445e0 100644 --- a/stubs/jsonschema/jsonschema/_types.pyi +++ b/stubs/jsonschema/jsonschema/_types.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable, Iterable, Mapping +from typing import Callable, Iterable, Mapping def is_array(checker, instance) -> bool: ... def is_bool(checker, instance) -> bool: ... @@ -12,7 +12,7 @@ def is_any(checker, instance) -> bool: ... class TypeChecker: def __init__(self, type_checkers: Mapping[str, Callable[[object], bool]] = ...) -> None: ... def is_type(self, instance, type: str) -> bool: ... - def redefine(self, type: str, fn: Callable[..., Any]) -> TypeChecker: ... + def redefine(self, type: str, fn: Callable[..., bool]) -> TypeChecker: ... def redefine_many(self, definitions=...) -> TypeChecker: ... def remove(self, *types: Iterable[str]) -> TypeChecker: ... From 0c7803c5f7cb06eaba4f2b9d8e95bd86c71e29e3 Mon Sep 17 00:00:00 2001 From: "Michael A. Smith" Date: Mon, 6 Dec 2021 10:59:57 -0500 Subject: [PATCH 14/14] Fix Failing CI --- stubs/jsonschema/jsonschema/_utils.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stubs/jsonschema/jsonschema/_utils.pyi b/stubs/jsonschema/jsonschema/_utils.pyi index 28b6ac1dea87..448be7e91cfa 100644 --- a/stubs/jsonschema/jsonschema/_utils.pyi +++ b/stubs/jsonschema/jsonschema/_utils.pyi @@ -16,9 +16,9 @@ def load_schema(name): ... def format_as_index(container: str, indices) -> str: ... def find_additional_properties(instance: Iterable[Any], schema: Mapping[Any, Any]) -> Generator[Any, None, None]: ... def extras_msg(extras: Iterable[Any] | Sized) -> str: ... -def ensure_list(thing) -> list: ... +def ensure_list(thing) -> list[Any]: ... def equal(one, two) -> bool: ... def unbool(element, true=..., false=...): ... def uniq(container) -> bool: ... -def find_evaluated_item_indexes_by_schema(validator, instance, schema) -> list: ... -def find_evaluated_property_keys_by_schema(validator, instance, schema) -> list: ... +def find_evaluated_item_indexes_by_schema(validator, instance, schema) -> list[Any]: ... +def find_evaluated_property_keys_by_schema(validator, instance, schema) -> list[Any]: ...