From 937d31df697620c711f0fddbf4df33ee1bcc9d65 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Thu, 15 Jul 2021 16:28:57 +0100 Subject: [PATCH] Stubs for jsonschema (#5784) --- pyrightconfig.stricter.json | 1 + .../jsonschema/@tests/stubtest_allowlist.txt | 13 +++ stubs/jsonschema/METADATA.toml | 1 + stubs/jsonschema/jsonschema/__init__.pyi | 23 ++++++ stubs/jsonschema/jsonschema/_format.pyi | 35 ++++++++ .../jsonschema/_legacy_validators.pyi | 8 ++ stubs/jsonschema/jsonschema/_reflect.pyi | 7 ++ stubs/jsonschema/jsonschema/_types.pyi | 26 ++++++ stubs/jsonschema/jsonschema/_utils.pyi | 25 ++++++ stubs/jsonschema/jsonschema/_validators.pyi | 32 ++++++++ stubs/jsonschema/jsonschema/cli.pyi | 10 +++ stubs/jsonschema/jsonschema/compat.pyi | 0 stubs/jsonschema/jsonschema/exceptions.pyi | 81 +++++++++++++++++++ stubs/jsonschema/jsonschema/validators.pyi | 62 ++++++++++++++ 14 files changed, 324 insertions(+) create mode 100644 stubs/jsonschema/@tests/stubtest_allowlist.txt create mode 100644 stubs/jsonschema/METADATA.toml create mode 100644 stubs/jsonschema/jsonschema/__init__.pyi create mode 100644 stubs/jsonschema/jsonschema/_format.pyi create mode 100644 stubs/jsonschema/jsonschema/_legacy_validators.pyi create mode 100644 stubs/jsonschema/jsonschema/_reflect.pyi create mode 100644 stubs/jsonschema/jsonschema/_types.pyi create mode 100644 stubs/jsonschema/jsonschema/_utils.pyi create mode 100644 stubs/jsonschema/jsonschema/_validators.pyi create mode 100644 stubs/jsonschema/jsonschema/cli.pyi create mode 100644 stubs/jsonschema/jsonschema/compat.pyi create mode 100644 stubs/jsonschema/jsonschema/exceptions.pyi create mode 100644 stubs/jsonschema/jsonschema/validators.pyi diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index 23326c753..8fedbb53c 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -39,6 +39,7 @@ "stubs/httplib2", "stubs/Jinja2", "stubs/jmespath", + "stubs/jsonschema", "stubs/Markdown", "stubs/oauthlib", "stubs/Pillow", diff --git a/stubs/jsonschema/@tests/stubtest_allowlist.txt b/stubs/jsonschema/@tests/stubtest_allowlist.txt new file mode 100644 index 000000000..5f66c8101 --- /dev/null +++ b/stubs/jsonschema/@tests/stubtest_allowlist.txt @@ -0,0 +1,13 @@ +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 +jsonschema._format.is_iri +jsonschema._format.is_iri_reference +jsonschema._format.is_json_pointer +jsonschema._format.is_relative_json_pointer +jsonschema._format.is_time +jsonschema._format.is_uri +jsonschema._format.is_uri_reference +jsonschema._format.is_uri_template diff --git a/stubs/jsonschema/METADATA.toml b/stubs/jsonschema/METADATA.toml new file mode 100644 index 000000000..ffc5a1c5e --- /dev/null +++ b/stubs/jsonschema/METADATA.toml @@ -0,0 +1 @@ +version = "3.2" diff --git a/stubs/jsonschema/jsonschema/__init__.pyi b/stubs/jsonschema/jsonschema/__init__.pyi new file mode 100644 index 000000000..87b8e96f5 --- /dev/null +++ b/stubs/jsonschema/jsonschema/__init__.pyi @@ -0,0 +1,23 @@ +from jsonschema._format import ( + FormatChecker as FormatChecker, + 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, +) +from jsonschema._types import TypeChecker as TypeChecker +from jsonschema.exceptions import ( + ErrorTree as ErrorTree, + FormatError as FormatError, + RefResolutionError as RefResolutionError, + SchemaError as SchemaError, + ValidationError as ValidationError, +) +from jsonschema.validators import ( + Draft3Validator as Draft3Validator, + Draft4Validator as Draft4Validator, + Draft6Validator as Draft6Validator, + Draft7Validator as Draft7Validator, + RefResolver as RefResolver, + validate as validate, +) diff --git a/stubs/jsonschema/jsonschema/_format.pyi b/stubs/jsonschema/jsonschema/_format.pyi new file mode 100644 index 000000000..fdab126bb --- /dev/null +++ b/stubs/jsonschema/jsonschema/_format.pyi @@ -0,0 +1,35 @@ +from typing import Any + +class FormatChecker: + checkers: Any + def __init__(self, formats: Any | None = ...) -> None: ... + def checks(self, format, raises=...): ... + cls_checks: Any + 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 + +def is_email(instance): ... +def is_ipv4(instance): ... +def is_ipv6(instance): ... +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_css3_color(instance): ... +def is_json_pointer(instance): ... +def is_relative_json_pointer(instance): ... +def is_uri_template(instance, template_validator=...): ... diff --git a/stubs/jsonschema/jsonschema/_legacy_validators.pyi b/stubs/jsonschema/jsonschema/_legacy_validators.pyi new file mode 100644 index 000000000..40e61896d --- /dev/null +++ b/stubs/jsonschema/jsonschema/_legacy_validators.pyi @@ -0,0 +1,8 @@ +def dependencies_draft3(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 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: ... diff --git a/stubs/jsonschema/jsonschema/_reflect.pyi b/stubs/jsonschema/jsonschema/_reflect.pyi new file mode 100644 index 000000000..a19c6f9d8 --- /dev/null +++ b/stubs/jsonschema/jsonschema/_reflect.pyi @@ -0,0 +1,7 @@ +class _NoModuleFound(Exception): ... +class InvalidName(ValueError): ... +class ModuleNotFound(InvalidName): ... +class ObjectNotFound(InvalidName): ... + +def reraise(exception, traceback) -> None: ... +def namedAny(name): ... diff --git a/stubs/jsonschema/jsonschema/_types.pyi b/stubs/jsonschema/jsonschema/_types.pyi new file mode 100644 index 000000000..efbe6ba4e --- /dev/null +++ b/stubs/jsonschema/jsonschema/_types.pyi @@ -0,0 +1,26 @@ +from typing import Any + +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): ... + +class TypeChecker: + def is_type(self, instance, type): ... + 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 diff --git a/stubs/jsonschema/jsonschema/_utils.pyi b/stubs/jsonschema/jsonschema/_utils.pyi new file mode 100644 index 000000000..596ec6472 --- /dev/null +++ b/stubs/jsonschema/jsonschema/_utils.pyi @@ -0,0 +1,25 @@ +from typing import Any, MutableMapping + +class URIDict(MutableMapping[Any, Any]): + def normalize(self, uri): ... + store: 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): ... + +class Unset: ... + +def load_schema(name): ... +def indent(string, times: int = ...): ... +def format_as_index(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): ... diff --git a/stubs/jsonschema/jsonschema/_validators.pyi b/stubs/jsonschema/jsonschema/_validators.pyi new file mode 100644 index 000000000..8afcc3c07 --- /dev/null +++ b/stubs/jsonschema/jsonschema/_validators.pyi @@ -0,0 +1,32 @@ +def patternProperties(validator, patternProperties, instance, schema) -> None: ... +def propertyNames(validator, propertyNames, instance, schema) -> None: ... +def additionalProperties(validator, aP, instance, schema) -> None: ... +def items(validator, items, instance, schema) -> None: ... +def additionalItems(validator, aI, instance, schema) -> None: ... +def const(validator, const, instance, schema) -> None: ... +def contains(validator, contains, instance, schema) -> None: ... +def exclusiveMinimum(validator, minimum, instance, schema) -> None: ... +def exclusiveMaximum(validator, maximum, instance, schema) -> None: ... +def minimum(validator, minimum, instance, schema) -> None: ... +def maximum(validator, maximum, instance, schema) -> None: ... +def multipleOf(validator, dB, instance, schema) -> None: ... +def minItems(validator, mI, instance, schema) -> None: ... +def maxItems(validator, mI, instance, schema) -> None: ... +def uniqueItems(validator, uI, instance, schema) -> None: ... +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 enum(validator, enums, instance, schema) -> None: ... +def ref(validator, ref, instance, schema) -> None: ... +def type(validator, types, instance, schema) -> None: ... +def properties(validator, properties, instance, schema) -> None: ... +def required(validator, required, instance, schema) -> None: ... +def minProperties(validator, mP, instance, schema) -> None: ... +def maxProperties(validator, mP, instance, schema) -> None: ... +def allOf(validator, allOf, instance, schema) -> None: ... +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: ... diff --git a/stubs/jsonschema/jsonschema/cli.pyi b/stubs/jsonschema/jsonschema/cli.pyi new file mode 100644 index 000000000..1ccff3f60 --- /dev/null +++ b/stubs/jsonschema/jsonschema/cli.pyi @@ -0,0 +1,10 @@ +from typing import Any + +from jsonschema._reflect import namedAny as namedAny +from jsonschema.validators import validator_for as validator_for + +parser: Any + +def parse_args(args): ... +def main(args=...) -> None: ... +def run(arguments, stdout=..., stderr=...): ... diff --git a/stubs/jsonschema/jsonschema/compat.pyi b/stubs/jsonschema/jsonschema/compat.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/stubs/jsonschema/jsonschema/exceptions.pyi b/stubs/jsonschema/jsonschema/exceptions.pyi new file mode 100644 index 000000000..078d44b64 --- /dev/null +++ b/stubs/jsonschema/jsonschema/exceptions.pyi @@ -0,0 +1,81 @@ +from typing import Any + +WEAK_MATCHES: Any +STRONG_MATCHES: Any + +class _Error(Exception): + message: Any + path: Any + schema_path: Any + context: Any + cause: Any + validator: Any + validator_value: Any + instance: Any + schema: Any + parent: Any + def __init__( + self, + message, + validator=..., + path=..., + cause: Any | None = ..., + context=..., + validator_value=..., + instance=..., + schema=..., + 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): ... + +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 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 + def __init__(self, errors=...) -> None: ... + def __contains__(self, index): ... + def __getitem__(self, index): ... + def __setitem__(self, index, value) -> None: ... + def __iter__(self): ... + def __len__(self): ... + @property + def total_errors(self): ... + +def by_relevance(weak=..., strong=...): ... + +relevance: Any + +def best_match(errors, key=...): ... diff --git a/stubs/jsonschema/jsonschema/validators.pyi b/stubs/jsonschema/jsonschema/validators.pyi new file mode 100644 index 000000000..b9a078e60 --- /dev/null +++ b/stubs/jsonschema/jsonschema/validators.pyi @@ -0,0 +1,62 @@ +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 + +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 = ..., + id_of=..., +): ... +def extend(validator, validators=..., version: Any | None = ..., type_checker: Any | None = ...): ... + +Draft3Validator: Any +Draft4Validator: Any +Draft6Validator: Any +Draft7Validator: Any + +class RefResolver: + referrer: Any + cache_remote: Any + handlers: Any + store: Any + def __init__( + self, + base_uri, + referrer, + store=..., + cache_remote: bool = ..., + handlers=..., + urljoin_cache: Any | None = ..., + remote_cache: Any | None = ..., + ) -> None: ... + @classmethod + def from_schema(cls, schema, id_of=..., *args, **kwargs): ... + def push_scope(self, scope) -> None: ... + def pop_scope(self) -> None: ... + @property + def resolution_scope(self): ... + @property + def base_uri(self): ... + def in_scope(self, scope) -> None: ... + def resolving(self, ref) -> None: ... + def resolve(self, ref): ... + def resolve_from_url(self, url): ... + def resolve_fragment(self, document, fragment): ... + def resolve_remote(self, uri): ... + +def validate(instance, schema, cls: Any | None = ..., *args, **kwargs) -> None: ... +def validator_for(schema, default=...): ...