Fix RefResolver store parameter type in jsonschema stubs#15542
Fix RefResolver store parameter type in jsonschema stubs#15542srittau merged 5 commits intopython:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
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.
Change URIDict to use MutableMapping[str, Any] as the value type throughout, consistent with the actual runtime behavior where store values are schema documents (JSON objects), not plain strings. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
Since values() is called on the store mapping and RefResolver is deprecated, using Mapping directly is the more pragmatic approach. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
|
While I was switching |
| store: dict[str, MutableMapping[str, Any]] | ||
| def __init__( | ||
| self, | ||
| m: SupportsKeysAndGetItem[str, MutableMapping[str, Any]] | Iterable[tuple[str, MutableMapping[str, Any]]], |
There was a problem hiding this comment.
| m: SupportsKeysAndGetItem[str, MutableMapping[str, Any]] | Iterable[tuple[str, MutableMapping[str, Any]]], | |
| m: Mapping[str, MutableMapping[str, Any]] | Iterable[tuple[str, MutableMapping[str, Any]]], |
…tem for URIDict.__init__ m parameter Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Applied your suggestion — changed |
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
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: