Skip to content

Commit fabd842

Browse files
authored
Annotate parts of jsonschema.validators and URIDict (#7025)
1 parent a9ae6b2 commit fabd842

File tree

3 files changed

+55
-26
lines changed

3 files changed

+55
-26
lines changed

stubs/jsonschema/METADATA.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = "4.3.*"
1+
version = "4.4.*"

stubs/jsonschema/jsonschema/_utils.pyi

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
from typing import Any, Generator, Iterable, Mapping, MutableMapping, Sized
1+
from _typeshed import SupportsKeysAndGetItem
2+
from typing import Any, Generator, Iterable, Iterator, Mapping, MutableMapping, Sized
23

3-
class URIDict(MutableMapping[Any, Any]):
4+
class URIDict(MutableMapping[str, str]):
45
def normalize(self, uri: str) -> str: ...
5-
store: dict[Any, Any]
6-
def __init__(self, *args, **kwargs) -> None: ...
7-
def __getitem__(self, uri): ...
8-
def __setitem__(self, uri, value) -> None: ...
9-
def __delitem__(self, uri) -> None: ...
10-
def __iter__(self): ...
11-
def __len__(self): ...
6+
store: dict[str, str]
7+
def __init__(self, __m: SupportsKeysAndGetItem[str, str] | Iterable[tuple[str, str]], **kwargs: str) -> None: ...
8+
def __getitem__(self, uri: str) -> str: ...
9+
def __setitem__(self, uri: str, value: str) -> None: ...
10+
def __delitem__(self, uri: str) -> None: ...
11+
def __iter__(self) -> Iterator[str]: ...
12+
def __len__(self) -> int: ...
1213

1314
class Unset: ...
1415

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,56 @@
1-
from typing import Any, Callable
1+
from _typeshed import SupportsKeysAndGetItem
2+
from collections.abc import Callable, Generator, Iterable
3+
from typing import Any, ClassVar
4+
5+
from ._utils import URIDict
6+
7+
# This class does not exist at runtime. Compatible classes are created at
8+
# runtime by create().
9+
class _Validator:
10+
VALIDATORS: ClassVar[dict[Any, Any]]
11+
META_SCHEMA: ClassVar[dict[Any, Any]]
12+
TYPE_CHECKER: Any
13+
@staticmethod
14+
def ID_OF(): ...
15+
schema: Any
16+
resolver: Any
17+
format_checker: Any
18+
evolve: Any
19+
@classmethod
20+
def check_schema(cls, schema) -> None: ...
21+
def iter_errors(self, instance, _schema: Any | None = ...) -> Generator[Any, None, None]: ...
22+
def descend(self, instance, schema, path: Any | None = ..., schema_path: Any | None = ...) -> Generator[Any, None, None]: ...
23+
def validate(self, *args, **kwargs) -> None: ...
24+
def is_type(self, instance, type): ...
25+
def is_valid(self, instance, _schema: Any | None = ...) -> bool: ...
226

327
def validates(version: str) -> Callable[..., Any]: ...
4-
def create(meta_schema, validators=..., version: Any | None = ..., type_checker=..., id_of=..., applicable_validators=...): ...
28+
def create(
29+
meta_schema, validators=..., version: Any | None = ..., type_checker=..., id_of=..., applicable_validators=...
30+
) -> type[_Validator]: ...
531
def extend(validator, validators=..., version: Any | None = ..., type_checker: Any | None = ...): ...
632

7-
Draft3Validator: Any
8-
Draft4Validator: Any
9-
Draft6Validator: Any
10-
Draft7Validator: Any
11-
Draft201909Validator: Any
12-
Draft202012Validator: Any
33+
Draft3Validator: type[_Validator]
34+
Draft4Validator: type[_Validator]
35+
Draft6Validator: type[_Validator]
36+
Draft7Validator: type[_Validator]
37+
Draft201909Validator: type[_Validator]
38+
Draft202012Validator: type[_Validator]
39+
40+
_Handler = Callable[[str], Any]
1341

1442
class RefResolver:
15-
referrer: Any
43+
referrer: str
1644
cache_remote: Any
17-
handlers: Any
18-
store: Any
45+
handlers: dict[str, _Handler]
46+
store: URIDict
1947
def __init__(
2048
self,
21-
base_uri,
22-
referrer,
23-
store=...,
49+
base_uri: str,
50+
referrer: str,
51+
store: SupportsKeysAndGetItem[str, str] | Iterable[tuple[str, str]] = ...,
2452
cache_remote: bool = ...,
25-
handlers=...,
53+
handlers: SupportsKeysAndGetItem[str, _Handler] | Iterable[tuple[str, _Handler]] = ...,
2654
urljoin_cache: Any | None = ...,
2755
remote_cache: Any | None = ...,
2856
) -> None: ...
@@ -41,5 +69,5 @@ class RefResolver:
4169
def resolve_fragment(self, document, fragment): ...
4270
def resolve_remote(self, uri): ...
4371

44-
def validate(instance, schema, cls: Any | None = ..., *args, **kwargs) -> None: ...
72+
def validate(instance: object, schema: object, cls: type[_Validator] | None = ..., *args: Any, **kwargs: Any) -> None: ...
4573
def validator_for(schema, default=...): ...

0 commit comments

Comments
 (0)