Skip to content

Commit 59bcb31

Browse files
committed
Fix type checking for new jsonschema annotations
One fix is a `type:ignore` comment for a bad annotation which was introduced and then fixed. The other is the addition of an `if` check for an optional list which was being treated as non-optional.
1 parent 3e74c4a commit 59bcb31

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/check_jsonschema/formats.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,17 @@ def make_format_checker(
5050
formats.remove("regex")
5151
checker = jsonschema.FormatChecker(formats=formats)
5252

53+
# FIXME: type-ignore comments to handle incorrect annotation
54+
# fixed in https://github.com/python/typeshed/pull/7990
55+
# once available, remove the ignores
5356
if opts.regex_behavior == RegexFormatBehavior.disabled:
5457
pass
5558
elif opts.regex_behavior == RegexFormatBehavior.default:
56-
checker.checks("regex", raises=re.error)(_gated_regex_check)
59+
checker.checks("regex", raises=re.error)( # type: ignore[arg-type]
60+
_gated_regex_check
61+
)
5762
elif opts.regex_behavior == RegexFormatBehavior.python:
58-
checker.checks("regex", raises=re.error)(_regex_check)
63+
checker.checks("regex", raises=re.error)(_regex_check) # type: ignore[arg-type]
5964
else: # pragma: no cover
6065
raise NotImplementedError
6166

src/check_jsonschema/utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def print_error(err: Exception, mode: str = "short") -> None:
118118
def iter_validation_error(
119119
err: jsonschema.ValidationError,
120120
) -> t.Iterator[jsonschema.ValidationError]:
121-
for e in err.context:
122-
yield e
123-
yield from iter_validation_error(e)
121+
if err.context:
122+
for e in err.context:
123+
yield e
124+
yield from iter_validation_error(e)

0 commit comments

Comments
 (0)