From 74fb3d796d596f317915a113cf6ddb3e5a2528a1 Mon Sep 17 00:00:00 2001 From: dangotbanned <125183946+dangotbanned@users.noreply.github.com> Date: Fri, 12 Jul 2024 16:33:25 +0100 Subject: [PATCH] revert: Ignore type error introduced by `typeshed` The issue is not related to any runtime changes https://github.com/python-jsonschema/jsonschema/pull/1019#issuecomment-2225773286 --- altair/utils/schemapi.py | 19 ++++--------------- tools/schemapi/schemapi.py | 19 ++++--------------- 2 files changed, 8 insertions(+), 30 deletions(-) diff --git a/altair/utils/schemapi.py b/altair/utils/schemapi.py index 3e7c5ed68..f8e445064 100644 --- a/altair/utils/schemapi.py +++ b/altair/utils/schemapi.py @@ -409,20 +409,6 @@ def _group_errors_by_validator(errors: ValidationErrorList) -> GroupedValidation return dict(errors_by_validator) -def _safe_validator_value_iter(errors: ValidationErrorList, /) -> Iterator[str]: - for err in errors: - if isinstance(err.validator_value, Iterable): - yield ",".join(err.validator_value) - else: - msg = ( - "It is assumed that values (and therefore `validator_value`) of an enum are always arrays.\n" - "Therefore, this error should be unreachable.\n" - "see https://json-schema.org/understanding-json-schema/reference/generic.html#enumerated-values\n\n" - f"{type(err.validator_value).__name__!r} is not `Iterable`." - ) - raise TypeError(msg) - - def _deduplicate_enum_errors(errors: ValidationErrorList) -> ValidationErrorList: """Deduplicate enum errors by removing the errors where the allowed values are a subset of another error. For example, if `enum` contains two errors @@ -431,7 +417,10 @@ def _deduplicate_enum_errors(errors: ValidationErrorList) -> ValidationErrorList `enum` list only contains the error with ["A", "B", "C"]. """ if len(errors) > 1: - value_strings = list(_safe_validator_value_iter(errors)) + # Values (and therefore `validator_value`) of an enum are always arrays, + # see https://json-schema.org/understanding-json-schema/reference/generic.html#enumerated-values + # which is why we can use join below + value_strings = [",".join(err.validator_value) for err in errors] # type: ignore longest_enums: ValidationErrorList = [] for value_str, err in zip(value_strings, errors): if not _contained_at_start_of_one_of_other_values(value_str, value_strings): diff --git a/tools/schemapi/schemapi.py b/tools/schemapi/schemapi.py index dd1d3f452..22d0e2a28 100644 --- a/tools/schemapi/schemapi.py +++ b/tools/schemapi/schemapi.py @@ -407,20 +407,6 @@ def _group_errors_by_validator(errors: ValidationErrorList) -> GroupedValidation return dict(errors_by_validator) -def _safe_validator_value_iter(errors: ValidationErrorList, /) -> Iterator[str]: - for err in errors: - if isinstance(err.validator_value, Iterable): - yield ",".join(err.validator_value) - else: - msg = ( - "It is assumed that values (and therefore `validator_value`) of an enum are always arrays.\n" - "Therefore, this error should be unreachable.\n" - "see https://json-schema.org/understanding-json-schema/reference/generic.html#enumerated-values\n\n" - f"{type(err.validator_value).__name__!r} is not `Iterable`." - ) - raise TypeError(msg) - - def _deduplicate_enum_errors(errors: ValidationErrorList) -> ValidationErrorList: """Deduplicate enum errors by removing the errors where the allowed values are a subset of another error. For example, if `enum` contains two errors @@ -429,7 +415,10 @@ def _deduplicate_enum_errors(errors: ValidationErrorList) -> ValidationErrorList `enum` list only contains the error with ["A", "B", "C"]. """ if len(errors) > 1: - value_strings = list(_safe_validator_value_iter(errors)) + # Values (and therefore `validator_value`) of an enum are always arrays, + # see https://json-schema.org/understanding-json-schema/reference/generic.html#enumerated-values + # which is why we can use join below + value_strings = [",".join(err.validator_value) for err in errors] # type: ignore longest_enums: ValidationErrorList = [] for value_str, err in zip(value_strings, errors): if not _contained_at_start_of_one_of_other_values(value_str, value_strings):