typeshed icon indicating copy to clipboard operation
typeshed copied to clipboard

Is types-jsonschema outdated?

Open kratsg opened this issue 1 year ago • 15 comments

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).

kratsg avatar Sep 01 '22 20:09 kratsg

Yeah, the type for store definitely looks wrong. PR welcome!

hauntsaninja avatar Sep 01 '22 20:09 hauntsaninja

Cc. @sirosen, for interest :)

AlexWaygood avatar Sep 02 '22 08:09 AlexWaygood

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!)

sirosen avatar Sep 11 '22 19:09 sirosen