Fix RefResolver store parameter type in jsonschema stubs#15542
Fix RefResolver store parameter type in jsonschema stubs#15542sedat4ras wants to merge 1 commit intopython:mainfrom
Conversation
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
srittau
left a comment
There was a problem hiding this comment.
Thanks, one request below.
Also, I noticed that URIDict in _utils.pyi also derives from MutableMapping[str, str]. This should probably also be changed to MutableMapping[str, MutableMapping[str, Any]] (and of course some method types need to be changed as well.) You could include these changes in this PR if you want to, but that's optional.
| base_uri: str, | ||
| referrer: dict[str, Incomplete], | ||
| store: SupportsKeysAndGetItem[str, str] | Iterable[tuple[str, str]] = ..., | ||
| store: SupportsKeysAndGetItem[str, Mapping[str, Any]] | Iterable[tuple[str, Mapping[str, Any]]] = ..., |
There was a problem hiding this comment.
I just noticed something else: values() is called on store if it's a Mapping:
While we usually try to avoid Mapping in new annotations, considerung that RefResolver is deprecated and will be removed at some point, just using it here is probably the most pragmatic solution.
Fixes #8662
Changes
In
stubs/jsonschema/jsonschema/validators.pyi, thestoreparameter ofRefResolver.__init__was typed asSupportsKeysAndGetItem[str, str] | Iterable[tuple[str, str]], but the actual runtime implementation accepts a mapping/iterable ofMapping[str, Any](i.e., full JSON schema objects), not plainstrvalues.The jsonschema source code uses
URIDict(which inherits fromMutableMapping[str, Any]) for the store, and the store values are schema documents (JSON objects), not strings.Before:
After:
This matches the actual usage pattern where users pass schema documents as store values: