Skip to content

Commit 5134dd9

Browse files
committed
Resolve typing issues with referencing+mypy
Also setup a pyright tox environment for testing and usage.
1 parent 93edec3 commit 5134dd9

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/check_jsonschema/parsers/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __init__(
6565
}
6666

6767
def get(
68-
self, path: pathlib.Path, default_filetype: str
68+
self, path: pathlib.Path | str, default_filetype: str
6969
) -> t.Callable[[t.BinaryIO], t.Any]:
7070
filetype = path_to_type(path, default_type=default_filetype)
7171

src/check_jsonschema/schema_loader/resolver.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import referencing
88
import requests
9-
from referencing.jsonschema import DRAFT202012
9+
from referencing.jsonschema import DRAFT202012, Schema
1010

1111
from ..parsers import ParserSet
1212
from ..utils import filename2path
@@ -18,7 +18,9 @@ def make_reference_registry(
1818
schema_resource = referencing.Resource.from_contents(
1919
schema, default_specification=DRAFT202012
2020
)
21-
registry = referencing.Registry(
21+
# mypy does not recognize that Registry is an `attrs` class and has `retrieve` as an
22+
# argument to its implicit initializer
23+
registry: referencing.Registry = referencing.Registry( # type: ignore[call-arg]
2224
retrieve=create_retrieve_callable(parsers, schema_uri)
2325
)
2426

@@ -34,8 +36,8 @@ def make_reference_registry(
3436

3537
def create_retrieve_callable(
3638
parser_set: ParserSet, schema_uri: str | None
37-
) -> t.Callable[[str], referencing.Resource]:
38-
def get_local_file(uri: str):
39+
) -> t.Callable[[str], referencing.Resource[Schema]]:
40+
def get_local_file(uri: str) -> t.Any:
3941
path = pathlib.Path(uri)
4042
if not path.is_absolute():
4143
if schema_uri is None:
@@ -48,7 +50,7 @@ def get_local_file(uri: str):
4850
path = schema_path.parent / path
4951
return parser_set.parse_file(path, "json")
5052

51-
def retrieve_reference(uri: str) -> referencing.Resource:
53+
def retrieve_reference(uri: str) -> referencing.Resource[Schema]:
5254
scheme = urllib.parse.urlsplit(uri).scheme
5355
if scheme in ("http", "https"):
5456
data = requests.get(uri, stream=True)

tox.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ deps = mypy
5454
click==8.1.3
5555
commands = mypy src/ {posargs}
5656

57+
[testenv:pyright]
58+
description = "check type annotations with pyright"
59+
deps = pyright
60+
types-jsonschema
61+
types-requests
62+
commands = pyright src/ {posargs}
63+
5764
[testenv:docs]
5865
description = "build docs with sphinx"
5966
basepython = python3.10

0 commit comments

Comments
 (0)