Commit a916d8f
committed
Fix
The runtime init signature of a validator can be seen with `inspect`:
```pycon
>>> import inspect, jsonschema
>>> inspect.signature(jsonschema.validators.Draft7Validator.__init__)
<Signature (self, schema: 'referencing.jsonschema.Schema', resolver=None, format_checker: '_format.FormatChecker | None' = None, *, registry: 'referencing.jsonschema.SchemaRegistry' = <Registry (20 resources)>, _resolver=None) -> None>
```
This aligns the protocol's declared signature with that behavior more
exactly with the following changes:
`registry` is now keyword-only, not keyword-or-positional, and has a
default.
`resolver` is added to the declared signature, so users who are using
it won't see typing-time discrepancies with the runtime. It is marked
as `Any` and commented inline as deprecated, since it's unclear what
else we could do to indicate its status.
This means that code passing a resolver will continue to type check
(previously it would not).
`resolver` is the second keyword-or-positional and `format_checker` is
the third, meaning that a positional-only caller who passes, for
example: `Draft202012Validator(foo, None, bar)` will have `foo`
slotted as the schema and `bar` as the `format_checker`
This would primarily impact callers with positional-args calling
conventions, but is more reflective of what they'll see at runtime.
In order to remove `resolver` from the protocol signature, but match
the runtime signatures well, some kind of placeholder is needed to
indicate `format_checker` as positional-or-keyword. Or else, a large
number of overloads for `__init__` could be declared to try to
simulate its removal.Validator protocol init to match runtime1 parent de60f18 commit a916d8f
1 file changed
+4
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
| 111 | + | |
112 | 112 | | |
113 | | - | |
114 | | - | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
115 | 116 | | |
116 | 117 | | |
117 | 118 | | |
| |||
0 commit comments