Skip to content

Commit a95597d

Browse files
committed
Add Back Optional Validators and Refine Types
1 parent 5d99acc commit a95597d

File tree

6 files changed

+61
-57
lines changed

6 files changed

+61
-57
lines changed

stubs/jsonschema/@tests/stubtest_allowlist.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
jsonschema._format.is_css21_color
22
jsonschema._format.is_css_color_code
33
jsonschema._format.is_datetime
4+
jsonschema._format.is_duration
5+
jsonschema._format.is_host_name
46
jsonschema._format.is_idn_host_name
57
jsonschema._format.is_iri
68
jsonschema._format.is_iri_reference
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from typing import Any
1+
from typing import Any, Iterable
22

33
class FormatChecker:
44
checkers: Any
5-
def __init__(self, formats: Any | None = ...) -> None: ...
5+
def __init__(self, formats: Iterable | None = ...) -> None: ...
66
def checks(self, format, raises=...): ...
77
cls_checks: Any
88
def check(self, instance, format) -> None: ...
9-
def conforms(self, instance, format): ...
9+
def conforms(self, instance, format) -> bool: ...
1010

1111
draft3_format_checker: FormatChecker
1212
draft4_format_checker: FormatChecker
@@ -15,28 +15,28 @@ draft7_format_checker: FormatChecker
1515
draft201909_format_checker: FormatChecker
1616
draft202012_format_checker: FormatChecker
1717

18-
def is_email(instance): ...
19-
def is_ipv4(instance): ...
20-
def is_ipv6(instance): ...
18+
def is_email(instance) -> bool: ...
19+
def is_ipv4(instance) -> bool: ...
20+
def is_ipv6(instance) -> bool: ...
2121

2222
# is_host_name is only defined if fqdn is installed.
23-
# def is_host_name(instance): ...
24-
def is_idn_host_name(instance): ...
25-
def is_uri(instance): ...
26-
def is_uri_reference(instance): ...
27-
def is_iri(instance): ...
28-
def is_iri_reference(instance): ...
29-
def is_datetime(instance): ...
30-
def is_time(instance): ...
31-
def is_regex(instance): ...
32-
def is_date(instance): ...
33-
def is_draft3_time(instance): ...
34-
def is_css_color_code(instance): ...
35-
def is_css21_color(instance): ...
36-
def is_json_pointer(instance): ...
37-
def is_relative_json_pointer(instance): ...
38-
def is_uri_template(instance): ...
23+
def is_host_name(instance) -> bool: ...
24+
def is_idn_host_name(instance) -> bool: ...
25+
def is_uri(instance) -> bool: ...
26+
def is_uri_reference(instance) -> bool: ...
27+
def is_iri(instance) -> bool: ...
28+
def is_iri_reference(instance) -> bool: ...
29+
def is_datetime(instance) -> bool: ...
30+
def is_time(instance) -> bool: ...
31+
def is_regex(instance) -> bool: ...
32+
def is_date(instance) -> bool: ...
33+
def is_draft3_time(instance) -> bool: ...
34+
def is_css_color_code(instance) -> bool: ...
35+
def is_css21_color(instance) -> bool: ...
36+
def is_json_pointer(instance) -> bool: ...
37+
def is_relative_json_pointer(instance) -> bool: ...
38+
def is_uri_template(instance) -> bool: ...
3939

4040
# is_duration is only defined if isoduration is installed.
41-
# def is_duration(instance): ...
42-
def is_uuid(instance): ...
41+
def is_duration(instance) -> bool: ...
42+
def is_uuid(instance) -> bool: ...

stubs/jsonschema/jsonschema/_legacy_validators.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
def ignore_ref_siblings(schema): ...
1+
from typing import Any, ItemsView, Union
2+
3+
def ignore_ref_siblings(schema) -> Union[list[tuple[str, Any]], ItemsView]: ...
24
def dependencies_draft3(validator, dependencies, instance, schema) -> None: ...
35
def dependencies_draft4_draft6_draft7(validator, dependencies, instance, schema) -> None: ...
46
def disallow_draft3(validator, disallow, instance, schema) -> None: ...
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
from typing import Any, Callable, Mapping
1+
from typing import Callable, Iterable, Mapping
22

3-
def is_array(checker, instance): ...
4-
def is_bool(checker, instance): ...
5-
def is_integer(checker, instance): ...
6-
def is_null(checker, instance): ...
7-
def is_number(checker, instance): ...
8-
def is_object(checker, instance): ...
9-
def is_string(checker, instance): ...
10-
def is_any(checker, instance): ...
3+
def is_array(checker, instance) -> bool: ...
4+
def is_bool(checker, instance) -> bool: ...
5+
def is_integer(checker, instance) -> bool: ...
6+
def is_null(checker, instance) -> bool: ...
7+
def is_number(checker, instance) -> bool: ...
8+
def is_object(checker, instance) -> bool: ...
9+
def is_string(checker, instance) -> bool: ...
10+
def is_any(checker, instance) -> bool: ...
1111

1212
class TypeChecker:
1313
def __init__(self, type_checkers: Mapping[str, Callable[[object], bool]] = ...) -> None: ...
14-
def is_type(self, instance, type): ...
15-
def redefine(self, type, fn): ...
16-
def redefine_many(self, definitions=...): ...
17-
def remove(self, *types): ...
14+
def is_type(self, instance, type: str) -> bool: ...
15+
def redefine(self, type: str, fn: Callable) -> TypeChecker: ...
16+
def redefine_many(self, definitions=...) -> TypeChecker: ...
17+
def remove(self, *types: Iterable[str]) -> TypeChecker: ...
1818

19-
draft3_type_checker: Any
20-
draft4_type_checker: Any
21-
draft6_type_checker: Any
22-
draft7_type_checker: Any
23-
draft201909_type_checker: Any
24-
draft202012_type_checker: Any
19+
draft3_type_checker: TypeChecker
20+
draft4_type_checker: TypeChecker
21+
draft6_type_checker: TypeChecker
22+
draft7_type_checker: TypeChecker
23+
draft201909_type_checker: TypeChecker
24+
draft202012_type_checker: TypeChecker
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from typing import Any, MutableMapping
1+
from typing import Any, Generator, Iterable, Mapping, MutableMapping, Sized, Union
22

33
class URIDict(MutableMapping[Any, Any]):
4-
def normalize(self, uri): ...
5-
store: Any
4+
def normalize(self, uri: str) -> str: ...
5+
store: dict
66
def __init__(self, *args, **kwargs) -> None: ...
77
def __getitem__(self, uri): ...
88
def __setitem__(self, uri, value) -> None: ...
@@ -13,12 +13,12 @@ class URIDict(MutableMapping[Any, Any]):
1313
class Unset: ...
1414

1515
def load_schema(name): ...
16-
def format_as_index(container, indices): ...
17-
def find_additional_properties(instance, schema) -> None: ...
18-
def extras_msg(extras): ...
19-
def ensure_list(thing): ...
20-
def equal(one, two): ...
16+
def format_as_index(container: str, indices) -> str: ...
17+
def find_additional_properties(instance: Iterable, schema: Mapping) -> Generator: ...
18+
def extras_msg(extras: Union[Iterable, Sized]) -> str: ...
19+
def ensure_list(thing) -> list: ...
20+
def equal(one, two) -> bool: ...
2121
def unbool(element, true=..., false=...): ...
22-
def uniq(container): ...
23-
def find_evaluated_item_indexes_by_schema(validator, instance, schema): ...
24-
def find_evaluated_property_keys_by_schema(validator, instance, schema): ...
22+
def uniq(container) -> bool: ...
23+
def find_evaluated_item_indexes_by_schema(validator, instance, schema) -> list: ...
24+
def find_evaluated_property_keys_by_schema(validator, instance, schema) -> list: ...

stubs/jsonschema/jsonschema/validators.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from typing import Any
1+
from typing import Any, Callable
22

3-
def validates(version): ...
3+
def validates(version: str) -> Callable: ...
44
def create(meta_schema, validators=..., version: Any | None = ..., type_checker=..., id_of=..., applicable_validators=...): ...
55
def extend(validator, validators=..., version: Any | None = ..., type_checker: Any | None = ...): ...
66

0 commit comments

Comments
 (0)