Skip to content

Commit 8543de6

Browse files
authored
Patch type checking issues (#572)
These are issues with typeshed and some interpretation of `type[...]`. There aren't relevant runtime tweaks to apply, just notes on why these items are ignored.
1 parent 28fc9e2 commit 8543de6

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/check_jsonschema/formats/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,16 @@ def __init__(
5050

5151

5252
def get_base_format_checker(schema_dialect: str | None) -> jsonschema.FormatChecker:
53+
# mypy does not consider a class whose instances match a protocol to match
54+
# `type[$PROTOCOL]` so this is considered a mismatch
55+
default_validator_cls: type[jsonschema.Validator] = (
56+
jsonschema.Draft202012Validator # type:ignore[assignment]
57+
)
5358
# resolve the dialect, if given, to a validator class
5459
# default to the latest draft
5560
validator_class = jsonschema.validators.validator_for(
5661
{} if schema_dialect is None else {"$schema": schema_dialect},
57-
default=jsonschema.Draft202012Validator,
62+
default=default_validator_cls,
5863
)
5964
return validator_class.FORMAT_CHECKER
6065

src/check_jsonschema/schema_loader/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,11 @@ def _get_validator(
187187
validator_cls = _extend_with_pattern_implementation(validator_cls, regex_impl)
188188

189189
# now that we know it's safe to try to create the validator instance, do it
190-
validator = validator_cls(
190+
#
191+
# TODO: remove type ignore
192+
# mypy flags this because of an incorrect signature in typeshed
193+
# see: https://github.com/python/typeshed/pull/14327
194+
validator = validator_cls( # type: ignore[call-arg]
191195
schema,
192196
registry=reference_registry,
193197
format_checker=format_checker,

0 commit comments

Comments
 (0)