typeshed
typeshed copied to clipboard
Is types-jsonschema outdated?
ref: python-jsonschema/jsonschema#997
I expected the following code to work when it comes to typing
from typing import Any, Mapping
import jsonschema
store: dict[str, Mapping[str, Any]] = {}
jsonschema.RefResolver(
base_uri=f"file://mypath.json",
referrer={},
store=store
)
However, this gives an error:
test.py:9: error: Argument "store" to "RefResolver" has incompatible type "Dict[str, Mapping[str, Any]]"; expected "Union[SupportsKeysAndGetItem[str, str], Iterable[Tuple[str, str]]]" [arg-type]
Found 1 error in 1 file (checked 1 source file)
defined at https://github.com/python/typeshed/blob/c1d307fc3bf51488b708e1c71334faccba5fd294/stubs/jsonschema/jsonschema/validators.pyi#L66-L80 . It seems incorrect that store
is a dict[str, str]
type.
Similarly, referrer
is defined as a dict
(MutableMapping
) but I suspect that could be changed to Mapping
(generically).
Yeah, the type for store
definitely looks wrong. PR welcome!
Cc. @sirosen, for interest :)
I agree -- these seem like minor mistakes (and I bet git blame
shows my name! 😅 ). I'll try to work on this within the next couple of days.
For changing anything from dict
or MutableMapping
to Mapping
, I might want to get that changed in jsonschema
itself, first. That way, the type-checking on the library will match the contract being declared by the stubs.
(I'm just getting back to various things from a short break; thanks for the ping!)