Skip to content

Commit edc3e3a

Browse files
authored
[jsonschema] Add missing stubs (#14264)
1 parent aed8025 commit edc3e3a

File tree

7 files changed

+183
-42
lines changed

7 files changed

+183
-42
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Testing modules are not included in type stubs:
2+
jsonschema.tests.*
3+
jsonschema.benchmarks.*
4+
5+
# When importing this module, SystemExit: 2 is thrown:
6+
jsonschema.__main__
7+
8+
# Autogenerated methods using @attr.* decorators:
9+
jsonschema.Draft201909Validator.__attrs_attrs__
10+
jsonschema.Draft201909Validator.__attrs_own_setattr__
11+
jsonschema.Draft201909Validator.__attrs_post_init__
12+
jsonschema.Draft201909Validator.__match_args__
13+
jsonschema.Draft202012Validator.__attrs_attrs__
14+
jsonschema.Draft202012Validator.__attrs_own_setattr__
15+
jsonschema.Draft202012Validator.__attrs_post_init__
16+
jsonschema.Draft202012Validator.__match_args__
17+
jsonschema.Draft3Validator.__attrs_attrs__
18+
jsonschema.Draft3Validator.__attrs_own_setattr__
19+
jsonschema.Draft3Validator.__attrs_post_init__
20+
jsonschema.Draft3Validator.__match_args__
21+
jsonschema.Draft4Validator.__attrs_attrs__
22+
jsonschema.Draft4Validator.__attrs_own_setattr__
23+
jsonschema.Draft4Validator.__attrs_post_init__
24+
jsonschema.Draft4Validator.__match_args__
25+
jsonschema.Draft6Validator.__attrs_attrs__
26+
jsonschema.Draft6Validator.__attrs_own_setattr__
27+
jsonschema.Draft6Validator.__attrs_post_init__
28+
jsonschema.Draft6Validator.__match_args__
29+
jsonschema.Draft7Validator.__attrs_attrs__
30+
jsonschema.Draft7Validator.__attrs_own_setattr__
31+
jsonschema.Draft7Validator.__attrs_post_init__
32+
jsonschema.Draft7Validator.__match_args__
33+
jsonschema.RefResolutionError.__attrs_attrs__
34+
jsonschema.RefResolutionError.__match_args__
35+
jsonschema.TypeChecker.__attrs_attrs__
36+
jsonschema.TypeChecker.__match_args__
37+
jsonschema._types.TypeChecker.__attrs_attrs__
38+
jsonschema._types.TypeChecker.__match_args__
39+
jsonschema.cli._Outputter.__attrs_attrs__
40+
jsonschema.cli._Outputter.__attrs_own_setattr__
41+
jsonschema.cli._Outputter.__match_args__
42+
jsonschema.cli._PlainFormatter.__attrs_attrs__
43+
jsonschema.cli._PlainFormatter.__attrs_own_setattr__
44+
jsonschema.cli._PlainFormatter.__match_args__
45+
jsonschema.cli._PrettyFormatter.__attrs_attrs__
46+
jsonschema.cli._PrettyFormatter.__attrs_own_setattr__
47+
jsonschema.cli._PrettyFormatter.__match_args__
48+
jsonschema.exceptions.RefResolutionError.__attrs_attrs__
49+
jsonschema.exceptions.RefResolutionError.__match_args__
50+
jsonschema.validators.Draft201909Validator.__attrs_attrs__
51+
jsonschema.validators.Draft201909Validator.__attrs_own_setattr__
52+
jsonschema.validators.Draft201909Validator.__attrs_post_init__
53+
jsonschema.validators.Draft201909Validator.__match_args__
54+
jsonschema.validators.Draft202012Validator.__attrs_attrs__
55+
jsonschema.validators.Draft202012Validator.__attrs_own_setattr__
56+
jsonschema.validators.Draft202012Validator.__attrs_post_init__
57+
jsonschema.validators.Draft202012Validator.__match_args__
58+
jsonschema.validators.Draft3Validator.__attrs_attrs__
59+
jsonschema.validators.Draft3Validator.__attrs_own_setattr__
60+
jsonschema.validators.Draft3Validator.__attrs_post_init__
61+
jsonschema.validators.Draft3Validator.__match_args__
62+
jsonschema.validators.Draft4Validator.__attrs_attrs__
63+
jsonschema.validators.Draft4Validator.__attrs_own_setattr__
64+
jsonschema.validators.Draft4Validator.__attrs_post_init__
65+
jsonschema.validators.Draft4Validator.__match_args__
66+
jsonschema.validators.Draft6Validator.__attrs_attrs__
67+
jsonschema.validators.Draft6Validator.__attrs_own_setattr__
68+
jsonschema.validators.Draft6Validator.__attrs_post_init__
69+
jsonschema.validators.Draft6Validator.__match_args__
70+
jsonschema.validators.Draft7Validator.__attrs_attrs__
71+
jsonschema.validators.Draft7Validator.__attrs_own_setattr__
72+
jsonschema.validators.Draft7Validator.__attrs_post_init__
73+
jsonschema.validators.Draft7Validator.__match_args__
74+
# >= Python 3.13
75+
jsonschema.Draft201909Validator.__replace__
76+
jsonschema.Draft202012Validator.__replace__
77+
jsonschema.Draft3Validator.__replace__
78+
jsonschema.Draft4Validator.__replace__
79+
jsonschema.Draft6Validator.__replace__
80+
jsonschema.Draft7Validator.__replace__
81+
jsonschema.RefResolutionError.__replace__
82+
jsonschema.TypeChecker.__replace__
83+
jsonschema._types.TypeChecker.__replace__
84+
jsonschema.cli._Outputter.__replace__
85+
jsonschema.cli._PlainFormatter.__replace__
86+
jsonschema.cli._PrettyFormatter.__replace__
87+
jsonschema.exceptions.RefResolutionError.__replace__
88+
jsonschema.validators.Draft201909Validator.__replace__
89+
jsonschema.validators.Draft202012Validator.__replace__
90+
jsonschema.validators.Draft3Validator.__replace__
91+
jsonschema.validators.Draft4Validator.__replace__
92+
jsonschema.validators.Draft6Validator.__replace__
93+
jsonschema.validators.Draft7Validator.__replace__

stubs/jsonschema/METADATA.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
version = "4.24.*"
22
upstream_repository = "https://github.com/python-jsonschema/jsonschema"
33
requires = ["referencing"]
4-
partial_stub = true
54

65
[tool.stubtest]
7-
ignore_missing_stub = true
86
extras = ["format"]

stubs/jsonschema/jsonschema/__init__.pyi

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,17 @@ from jsonschema.validators import (
2626
RefResolver as RefResolver,
2727
validate as validate,
2828
)
29+
30+
__all__ = [
31+
"Draft3Validator",
32+
"Draft4Validator",
33+
"Draft6Validator",
34+
"Draft7Validator",
35+
"Draft201909Validator",
36+
"Draft202012Validator",
37+
"FormatChecker",
38+
"SchemaError",
39+
"TypeChecker",
40+
"ValidationError",
41+
"validate",
42+
]

stubs/jsonschema/jsonschema/_types.pyi

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
from _typeshed import Unused
12
from collections.abc import Callable, Iterable, Mapping
3+
from typing import Literal
24

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: ...
5+
def is_array(checker: Unused, instance: object) -> bool: ...
6+
def is_bool(checker: Unused, instance: object) -> bool: ...
7+
def is_integer(checker: Unused, instance: object) -> bool: ...
8+
def is_null(checker: Unused, instance: object) -> bool: ...
9+
def is_number(checker: Unused, instance: object) -> bool: ...
10+
def is_object(checker: Unused, instance: object) -> bool: ...
11+
def is_string(checker: Unused, instance: object) -> bool: ...
12+
def is_any(checker: Unused, instance: Unused) -> Literal[True]: ...
1113

1214
class TypeChecker:
1315
def __init__(self, type_checkers: Mapping[str, Callable[[object], bool]] = ...) -> None: ...
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
from _typeshed import Incomplete, SupportsKeysAndGetItem, SupportsNext
2-
from collections.abc import Generator, Iterable, Iterator, Mapping, MutableMapping, Sized
1+
from _typeshed import Incomplete, SupportsKeysAndGetItem, SupportsNext, SupportsRichComparison
2+
from collections.abc import Generator, Iterable, Iterator, Mapping, MutableMapping
3+
from typing import Literal, TypeVar, overload
4+
5+
_T = TypeVar("_T")
36

47
class URIDict(MutableMapping[str, str]):
58
def normalize(self, uri: str) -> str: ...
@@ -13,15 +16,16 @@ class URIDict(MutableMapping[str, str]):
1316

1417
class Unset: ...
1518

16-
def format_as_index(container: str, indices) -> str: ...
17-
def find_additional_properties(
18-
instance: Iterable[Incomplete], schema: Mapping[Incomplete, Incomplete]
19-
) -> Generator[Incomplete, None, None]: ...
20-
def extras_msg(extras: Iterable[Incomplete] | Sized) -> str: ...
21-
def ensure_list(thing) -> list[Incomplete]: ...
19+
def format_as_index(container: str, indices: Iterable[Incomplete] | None) -> str: ...
20+
def find_additional_properties(instance: Iterable[str], schema: Mapping[str, Iterable[str]]) -> Generator[str]: ...
21+
def extras_msg(extras: Iterable[object]) -> tuple[str, Literal["was", "were"]]: ... # elements are passed to the repr() function
22+
@overload
23+
def ensure_list(thing: str) -> list[str]: ...
24+
@overload
25+
def ensure_list(thing: _T) -> _T: ...
2226
def equal(one, two) -> bool: ...
2327
def unbool(element, true=..., false=...): ...
24-
def uniq(container) -> bool: ...
28+
def uniq(container: Iterable[SupportsRichComparison]) -> bool: ...
2529
def find_evaluated_item_indexes_by_schema(validator, instance, schema) -> list[Incomplete]: ...
2630
def find_evaluated_property_keys_by_schema(validator, instance, schema) -> list[Incomplete]: ...
2731
def is_valid(errs_it: SupportsNext[object]) -> bool: ...

stubs/jsonschema/jsonschema/cli.pyi

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,62 @@
1-
from _typeshed import Incomplete
1+
import argparse
2+
from _typeshed import ExcInfo, FileDescriptorOrPath, Incomplete, OptExcInfo, SupportsWrite
3+
from collections.abc import Mapping, Sequence
4+
from typing import Any
5+
from typing_extensions import Self, deprecated
26

7+
@deprecated("The jsonschema CLI is deprecated and will be removed in a future version. Please use check-jsonschema instead.")
38
class _CannotLoadFile(Exception): ...
49

10+
@deprecated("The jsonschema CLI is deprecated and will be removed in a future version. Please use check-jsonschema instead.")
511
class _Outputter:
6-
def __init__(self, formatter, stdout, stderr): ...
12+
_formatter: _PlainFormatter | _PrettyFormatter
13+
_stdout: SupportsWrite[str]
14+
_stderr: SupportsWrite[str]
15+
16+
def __init__(
17+
self, formatter: _PlainFormatter | _PrettyFormatter, stdout: SupportsWrite[str], stderr: SupportsWrite[str]
18+
) -> None: ...
719
@classmethod
8-
def from_arguments(cls, arguments, stdout, stderr): ...
9-
def load(self, path): ...
10-
def filenotfound_error(self, **kwargs) -> None: ...
11-
def parsing_error(self, **kwargs) -> None: ...
12-
def validation_error(self, **kwargs) -> None: ...
13-
def validation_success(self, **kwargs) -> None: ...
20+
def from_arguments(
21+
cls, arguments: Mapping[str, Incomplete], stdout: SupportsWrite[str], stderr: SupportsWrite[str]
22+
) -> Self: ...
23+
def load(self, path: FileDescriptorOrPath) -> Any: ... # result of json.load()
24+
def filenotfound_error(self, *, path: FileDescriptorOrPath, exc_info: OptExcInfo) -> None: ...
25+
def parsing_error(self, *, path: FileDescriptorOrPath, exc_info: ExcInfo) -> None: ...
26+
def validation_error(self, *, instance_path: FileDescriptorOrPath, error: BaseException) -> None: ...
27+
def validation_success(self, *, instance_path: FileDescriptorOrPath) -> None: ...
1428

29+
@deprecated("The jsonschema CLI is deprecated and will be removed in a future version. Please use check-jsonschema instead.")
1530
class _PrettyFormatter:
16-
def filenotfound_error(self, path, exc_info): ...
17-
def parsing_error(self, path, exc_info): ...
18-
def validation_error(self, instance_path, error): ...
19-
def validation_success(self, instance_path): ...
31+
_ERROR_MSG: str
32+
_SUCCESS_MSG: str
33+
34+
def __init__(self) -> None: ...
35+
def filenotfound_error(self, path: FileDescriptorOrPath, exc_info: OptExcInfo) -> str: ...
36+
def parsing_error(self, path: FileDescriptorOrPath, exc_info: ExcInfo) -> str: ...
37+
def validation_error(self, instance_path: FileDescriptorOrPath, error: BaseException) -> str: ...
38+
def validation_success(self, instance_path: FileDescriptorOrPath) -> str: ...
2039

40+
@deprecated("The jsonschema CLI is deprecated and will be removed in a future version. Please use check-jsonschema instead.")
2141
class _PlainFormatter:
22-
def __init__(self, error_format): ...
23-
def filenotfound_error(self, path, exc_info): ...
24-
def parsing_error(self, path, exc_info): ...
25-
def validation_error(self, instance_path, error): ...
26-
def validation_success(self, instance_path): ...
42+
_error_format: str
43+
44+
def __init__(self, error_format: str) -> None: ...
45+
def filenotfound_error(self, path: FileDescriptorOrPath, exc_info: OptExcInfo) -> str: ...
46+
def parsing_error(self, path: FileDescriptorOrPath, exc_info: ExcInfo) -> str: ...
47+
def validation_error(self, instance_path: FileDescriptorOrPath, error: BaseException) -> str: ...
48+
def validation_success(self, instance_path: FileDescriptorOrPath) -> str: ...
2749

28-
parser: Incomplete
50+
parser: argparse.ArgumentParser
2951

30-
def parse_args(args): ...
31-
def main(args=...) -> None: ...
32-
def run(arguments, stdout=..., stderr=..., stdin=...): ...
52+
@deprecated("The jsonschema CLI is deprecated and will be removed in a future version. Please use check-jsonschema instead.")
53+
def parse_args(args: Sequence[str] | None) -> dict[str, Any]: ... # result of vars(argparse.Namespace())
54+
@deprecated("The jsonschema CLI is deprecated and will be removed in a future version. Please use check-jsonschema instead.")
55+
def main(args: Sequence[str] = ...) -> None: ...
56+
@deprecated("The jsonschema CLI is deprecated and will be removed in a future version. Please use check-jsonschema instead.")
57+
def run(
58+
arguments: Mapping[str, Incomplete],
59+
stdout: SupportsWrite[str] = ...,
60+
stderr: SupportsWrite[str] = ...,
61+
stdin: SupportsWrite[str] = ...,
62+
) -> int: ...

stubs/jsonschema/jsonschema/validators.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class _Validator:
5454
def iter_errors(self, instance, _schema: Schema | None) -> Generator[Incomplete]: ...
5555
def descend(
5656
self, instance, schema: Schema, path: Incomplete | None = ..., schema_path: Incomplete | None = ..., resolver=None
57-
) -> Generator[Incomplete, None, None]: ...
57+
) -> Generator[Incomplete]: ...
5858
def validate(self, *args, **kwargs) -> None: ...
5959
def is_type(self, instance, type) -> bool: ...
6060
@overload
@@ -63,7 +63,7 @@ class _Validator:
6363
@deprecated("Passing a schema to Validator.is_valid is deprecated and will be removed in a future release.")
6464
def is_valid(self, instance, _schema: Schema | None) -> bool: ...
6565

66-
def validates(version: str) -> Callable[..., Incomplete]: ...
66+
def validates(version: str) -> Callable[[_Validator], _Validator]: ...
6767
def create(
6868
meta_schema: Schema,
6969
validators: Mapping[str, _ValidatorCallback] | tuple[()] = (),

0 commit comments

Comments
 (0)