simplibs-rules 0.3.0__tar.gz → 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {simplibs_rules-0.3.0/src/simplibs_rules.egg-info → simplibs_rules-0.5.0}/PKG-INFO +30 -16
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/README.md +26 -13
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/pyproject.toml +19 -6
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/__init__.py +30 -10
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/containers/ForEach.py +19 -0
- simplibs_rules-0.5.0/src/simplibs/rules/containers/ForEachKey.py +158 -0
- simplibs_rules-0.5.0/src/simplibs/rules/containers/ForEachValue.py +160 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/containers/__init__.py +5 -1
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/containers/_helpers/__init__.py +11 -4
- simplibs_rules-0.5.0/src/simplibs/rules/containers/_helpers/format_key_label.py +42 -0
- simplibs_rules-0.5.0/src/simplibs/rules/containers/_helpers/format_value_label.py +43 -0
- simplibs_rules-0.5.0/src/simplibs/rules/containers/_helpers/shorten_repr.py +45 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/containers/_init_validators/__init__.py +1 -1
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/containers/_init_validators/raise_rule_param_not_callable.py +8 -2
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/collections/AllUnique.py +43 -9
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/collections/IsSubsetOf.py +42 -8
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/collections/IsSupersetOf.py +42 -8
- simplibs_rules-0.5.0/src/simplibs/rules/predicates/introspection/IsReiterable.py +133 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/introspection/__init__.py +14 -12
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/typing/_builders/build_elements_rule.py +41 -4
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/typing/_builders/build_key_value_rule.py +76 -64
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0/src/simplibs_rules.egg-info}/PKG-INFO +30 -16
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs_rules.egg-info/SOURCES.txt +8 -1
- simplibs_rules-0.5.0/src/simplibs_rules.egg-info/requires.txt +6 -0
- simplibs_rules-0.5.0/tests/test_package_exports.py +94 -0
- simplibs_rules-0.3.0/src/simplibs_rules.egg-info/requires.txt +0 -5
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/LICENSE +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/setup.cfg +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/base_class/Rule.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/base_class/_NotARule.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/base_class/__init__.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/containers/AllOf.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/containers/AnyOf.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/containers/Compose.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/containers/Described.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/containers/NoneOf.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/containers/Not.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/containers/_helpers/as_predicate.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/containers/_helpers/build_child_exception.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/containers/_helpers/describe_rule.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/containers/_helpers/validations/__init__.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/containers/_helpers/validations/raise_invalid_predicate.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/containers/_init_validators/raise_container_param_not_type_error.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/containers/_init_validators/raise_requires_at_least_one_rule_error.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/containers/_init_validators/validate_compose_param_is_callable.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/__init__.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/_helpers/__init__.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/_helpers/accepts_one_positional_argument.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/_helpers/format_container.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/_init_validators/__init__.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/_init_validators/rule_errors/__init__.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/_init_validators/rule_errors/raise_has_length_param_conflict_error.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/_init_validators/rule_errors/raise_regex_param_invalid_pattern_error.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/_init_validators/rule_errors/raise_user_rule_param_wrong_arity.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/_init_validators/shared_errors/__init__.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/_init_validators/shared_errors/raise_param_min_max_bounds_inverted_error.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/_init_validators/shared_errors/raise_param_min_max_incomparable_error.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/_init_validators/shared_errors/raise_param_missing_error.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/_init_validators/shared_errors/raise_param_not_callable_error.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/_init_validators/shared_errors/raise_param_not_container_error.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/_init_validators/shared_errors/raise_param_not_non_negative_integer_error.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/_init_validators/shared_errors/raise_param_not_string_error.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/_init_validators/shared_errors/raise_param_not_type_error.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/_init_validators/shared_validators/__init__.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/_init_validators/shared_validators/validate_param_is_integer.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/_init_validators/shared_validators/validate_param_is_not_zero.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/_init_validators/shared_validators/validate_param_is_primitive_number.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/_init_validators/shared_validators/validate_param_remainder_in_range.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/arithmetic/CloseTo.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/arithmetic/DivisibleBy.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/arithmetic/HasRemainder.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/arithmetic/__init__.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/checkers/IsEmpty.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/checkers/IsFalse.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/checkers/IsNone.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/checkers/IsTrue.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/checkers/NotEmpty.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/checkers/__init__.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/collections/HasItem.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/collections/HasKey.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/collections/HasKeys.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/collections/IsContainer.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/collections/__init__.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/comparisons/Equals.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/comparisons/GreaterOrEqual.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/comparisons/GreaterThan.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/comparisons/InRange.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/comparisons/LessOrEqual.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/comparisons/LessThan.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/comparisons/NotEquals.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/comparisons/__init__.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/introspection/HasAttribute.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/introspection/HasLength.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/introspection/IsCallable.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/introspection/IsDataclass.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/introspection/IsHashable.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/introspection/IsInstance.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/introspection/IsIterable.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/introspection/IsSubclass.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/introspection/IsType.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/logic/Is.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/logic/IsIn.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/logic/IsNot.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/logic/NotIn.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/logic/UserRule.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/logic/__init__.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/numeric/IsBool.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/numeric/IsDecimal.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/numeric/IsEven.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/numeric/IsFinite.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/numeric/IsFloat.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/numeric/IsInfinity.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/numeric/IsInteger.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/numeric/IsNan.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/numeric/IsNumber.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/numeric/IsOdd.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/numeric/IsPi.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/numeric/IsPrimitiveNumber.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/numeric/IsZero.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/numeric/__init__.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/strings/Contains.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/strings/EndsWith.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/strings/IsAlnum.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/strings/IsAlpha.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/strings/IsAscii.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/strings/IsBlank.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/strings/IsDigitString.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/strings/IsIdentifier.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/strings/IsLowercase.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/strings/IsPrintable.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/strings/IsString.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/strings/IsSubstringOf.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/strings/IsTitlecase.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/strings/IsUppercase.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/strings/IsWhitespace.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/strings/NotBlank.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/strings/Regex.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/strings/StartsWith.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/strings/__init__.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/typing/IsAny.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/typing/IsTyping.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/typing/__init__.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/typing/_builders/ORIGIN_TABLE.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/typing/_builders/__init__.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/typing/_builders/build_annotated_rule.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/typing/_builders/build_any_of_rule.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/typing/_builders/build_callable_rule.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/typing/_builders/build_literal_rule.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/typing/_builders/build_tuple_rule.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/typing/_builders/build_type_rule.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/typing/_helpers/__init__.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/typing/_helpers/format_annotation.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/typing/_validations/__init__.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/typing/_validations/raise_unsupported_annotation_error.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/typing/build_typing_rule.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/typing/tools/__init__.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/typing/tools/get_supported_origins.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/predicates/typing/tools/is_supported_annotation.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/testing/__init__.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/testing/assert_rule_contract.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/testing/asserts/__init__.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/testing/asserts/assert_rule_build_exception.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/testing/asserts/assert_rule_describe.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/testing/asserts/assert_rule_is_valid.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/testing/asserts/assert_rule_param_error.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/testing/asserts/assert_rule_slots.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs/rules/testing/asserts/assert_rule_validate.py +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs_rules.egg-info/dependency_links.txt +0 -0
- {simplibs_rules-0.3.0 → simplibs_rules-0.5.0}/src/simplibs_rules.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: simplibs-rules
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: Composable, explicit validation rules — pure predicates, zero transformation.
|
|
5
5
|
Author-email: "Dalibor Sova (Sudip2708)" <daliborsova@seznam.cz>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -20,10 +20,11 @@ Classifier: Topic :: Software Development :: Testing
|
|
|
20
20
|
Requires-Python: >=3.11
|
|
21
21
|
Description-Content-Type: text/markdown
|
|
22
22
|
License-File: LICENSE
|
|
23
|
-
Requires-Dist: simplibs-exception>=1.1.
|
|
23
|
+
Requires-Dist: simplibs-exception>=1.1.4
|
|
24
24
|
Requires-Dist: simplibs-sentinels>=0.2.0
|
|
25
25
|
Provides-Extra: dev
|
|
26
|
-
Requires-Dist: pytest>=
|
|
26
|
+
Requires-Dist: pytest>=9.0; extra == "dev"
|
|
27
|
+
Requires-Dist: pytest-cov>=5.0; extra == "dev"
|
|
27
28
|
Dynamic: license-file
|
|
28
29
|
|
|
29
30
|
# 📏 `simplibs-rules`
|
|
@@ -31,6 +32,7 @@ Dynamic: license-file
|
|
|
31
32
|
[](https://pypi.org/project/simplibs-rules/)
|
|
32
33
|
[](https://www.python.org/downloads/)
|
|
33
34
|
[](https://github.com/simplibs/simplibs-rules/blob/main/LICENSE)
|
|
35
|
+
[](https://github.com/simplibs/simplibs-rules/actions)
|
|
34
36
|
|
|
35
37
|
**Composable, explicit validation rules — pure predicates, zero transformation.**
|
|
36
38
|
|
|
@@ -119,7 +121,7 @@ rule = is_integer & greater_than(0)
|
|
|
119
121
|
rule.validate(5) # -> True
|
|
120
122
|
rule.validate(5, return_value=True) # -> 5
|
|
121
123
|
rule.validate(-5, return_bool=True) # -> False
|
|
122
|
-
rule.validate(-5) # -> raises
|
|
124
|
+
rule.validate(-5) # -> raises ValidationError
|
|
123
125
|
```
|
|
124
126
|
|
|
125
127
|
### Level 3: Annotation-driven rules
|
|
@@ -132,6 +134,9 @@ typing_rule = IsTyping(dict[str, int])
|
|
|
132
134
|
|
|
133
135
|
typing_rule.is_valid({"apples": 5, "oranges": 10}) # -> True
|
|
134
136
|
typing_rule.is_valid({"apples": "5"}) # -> False
|
|
137
|
+
|
|
138
|
+
# A failing entry is named by its key, not by its position:
|
|
139
|
+
typing_rule.validate({"apples": "5"}, value_name="stock") # fails at stock['apples']
|
|
135
140
|
```
|
|
136
141
|
|
|
137
142
|
### Level 4: Readable descriptions
|
|
@@ -158,13 +163,13 @@ src/simplibs/rules/
|
|
|
158
163
|
├── base_class/ ◄── Abstract base class Rule & internal helpers (_NotARule)
|
|
159
164
|
│ ├── Rule.py
|
|
160
165
|
│ └── _NotARule.py
|
|
161
|
-
├── containers/ ◄── Rule combinators (AllOf, AnyOf, Not, NoneOf, ForEach, Compose, Described)
|
|
166
|
+
├── containers/ ◄── Rule combinators (AllOf, AnyOf, Not, NoneOf, ForEach, ForEachKey, ForEachValue, Compose, Described)
|
|
162
167
|
├── predicates/ ◄── Single-purpose predicate rules
|
|
163
168
|
│ ├── arithmetic/ ◄── CloseTo, DivisibleBy, HasRemainder
|
|
164
169
|
│ ├── checkers/ ◄── IsEmpty, NotEmpty, IsNone, IsTrue, IsFalse
|
|
165
170
|
│ ├── collections/ ◄── IsContainer, HasItem, HasKey, HasKeys, AllUnique, IsSubsetOf, IsSupersetOf
|
|
166
171
|
│ ├── comparisons/ ◄── Equals, NotEquals, GreaterThan, GreaterOrEqual, LessThan, LessOrEqual, InRange
|
|
167
|
-
│ ├── introspection/ ◄── IsInstance, IsType, IsSubclass, IsDataclass, IsCallable, IsHashable, IsIterable, HasAttribute, HasLength
|
|
172
|
+
│ ├── introspection/ ◄── IsInstance, IsType, IsSubclass, IsDataclass, IsCallable, IsHashable, IsIterable, IsReiterable, HasAttribute, HasLength
|
|
168
173
|
│ ├── logic/ ◄── Is, IsNot, IsIn, NotIn, UserRule
|
|
169
174
|
│ ├── numeric/ ◄── IsBool, IsInteger, IsFloat, IsDecimal, IsNumber, IsPrimitiveNumber, IsZero, IsNan, IsInfinity, IsPi, IsEven, IsOdd, IsFinite
|
|
170
175
|
│ ├── strings/ ◄── IsString, Contains, IsSubstringOf, StartsWith, EndsWith, Regex, IsBlank, NotBlank, IsAlnum, IsAlpha, IsAscii, IsDigitString, IsLowercase, IsTitlecase, IsUppercase, IsIdentifier, IsPrintable, IsWhitespace
|
|
@@ -257,15 +262,17 @@ Both are fully interchangeable.
|
|
|
257
262
|
|
|
258
263
|
### `containers/` — Composing other rules
|
|
259
264
|
|
|
260
|
-
| Class
|
|
261
|
-
|
|
262
|
-
| `AllOf`
|
|
263
|
-
| `AnyOf`
|
|
264
|
-
| `Compose`
|
|
265
|
-
| `ForEach`
|
|
266
|
-
| `
|
|
267
|
-
| `
|
|
268
|
-
| `
|
|
265
|
+
| Class | Shortcut | Description / Parameters |
|
|
266
|
+
|----------------|------------------|---------------------------------------------------------------------------------------|
|
|
267
|
+
| `AllOf` | `all_of` | Logical AND across multiple rules (`*rules`). Behind `&`. |
|
|
268
|
+
| `AnyOf` | `any_of` | Logical OR across multiple rules (`*rules`). Behind `\|`. |
|
|
269
|
+
| `Compose` | `compose` | Transforms value before checking (`transformer, validator`). |
|
|
270
|
+
| `ForEach` | `for_each` | Validates every item in an iterable (`rule`). |
|
|
271
|
+
| `ForEachKey` | `for_each_key` | Validates every key of a mapping (`rule`). |
|
|
272
|
+
| `ForEachValue` | `for_each_value` | Validates every value of a mapping; a failing one is named by its key (`rule`). |
|
|
273
|
+
| `NoneOf` | `none_of` | Value must satisfy none of the given rules (`*rules`). |
|
|
274
|
+
| `Not` | `negate` | Logical NOT for a single rule (`rule`). Behind `~`. |
|
|
275
|
+
| `Described` | - | Behaves like the wrapped rule, but describes itself with a fixed text (`rule, text`). |
|
|
269
276
|
|
|
270
277
|
➡️ [README_RULE_CONTAINERS](https://github.com/simplibs/simplibs-rules/blob/main/docs/rules/README_RULE_CONTAINERS.md)
|
|
271
278
|
|
|
@@ -286,7 +293,7 @@ Both are fully interchangeable.
|
|
|
286
293
|
[README_RULE_PREDICATE_COMPARISONS](https://github.com/simplibs/simplibs-rules/blob/main/docs/rules/README_RULE_PREDICATE_COMPARISONS.md)
|
|
287
294
|
|
|
288
295
|
* **`introspection/`**: `IsInstance`, `IsType`, `IsSubclass`, `IsDataclass`,
|
|
289
|
-
`IsCallable`, `IsHashable`, `IsIterable`, `HasAttribute`, `HasLength`
|
|
296
|
+
`IsCallable`, `IsHashable`, `IsIterable`, `IsReiterable`, `HasAttribute`, `HasLength`
|
|
290
297
|
[README_RULE_PREDICATE_INTROSPECTION](https://github.com/simplibs/simplibs-rules/blob/main/docs/rules/README_RULE_PREDICATE_INTROSPECTION.md)
|
|
291
298
|
|
|
292
299
|
* **`logic/`**: `Is`, `IsNot`, `IsIn`, `NotIn`, `UserRule`
|
|
@@ -313,6 +320,13 @@ Both are fully interchangeable.
|
|
|
313
320
|
int] | None`, `Literal[...]`, `Callable[...]`, ...) into a composed `Rule` tree — the
|
|
314
321
|
mechanism that also powers `simplibs-validate`'s `validate_call`/`validate_dataclass`.
|
|
315
322
|
|
|
323
|
+
> **One-shot iterators:** `Iterable[T]` checks the value item by item, which would consume
|
|
324
|
+
> a generator, so a generator (or any other one-shot iterator) is **rejected** with a clear
|
|
325
|
+
> error instead of being passed on exhausted — see
|
|
326
|
+
> [`IsReiterable`](https://github.com/simplibs/simplibs-rules/blob/main/docs/rules/README_RULE_PREDICATE_INTROSPECTION.md#isreiterable).
|
|
327
|
+
> Plain `Iterable` still accepts generators; use a `list`/`tuple`/`set` (or `Collection[T]`)
|
|
328
|
+
> to have items checked.
|
|
329
|
+
|
|
316
330
|
➡️ [README_RULE_TYPING](https://github.com/simplibs/simplibs-rules/blob/main/docs/rules/README_RULE_TYPING.md) — the public `IsTyping`/`build_typing_rule` entry points
|
|
317
331
|
➡️ [README_RULE_TYPING_BUILDERS](https://github.com/simplibs/simplibs-rules/blob/main/docs/rules/README_RULE_TYPING_BUILDERS.md) — the internal per-construct decomposition engine
|
|
318
332
|
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
[](https://pypi.org/project/simplibs-rules/)
|
|
4
4
|
[](https://www.python.org/downloads/)
|
|
5
5
|
[](https://github.com/simplibs/simplibs-rules/blob/main/LICENSE)
|
|
6
|
+
[](https://github.com/simplibs/simplibs-rules/actions)
|
|
6
7
|
|
|
7
8
|
**Composable, explicit validation rules — pure predicates, zero transformation.**
|
|
8
9
|
|
|
@@ -91,7 +92,7 @@ rule = is_integer & greater_than(0)
|
|
|
91
92
|
rule.validate(5) # -> True
|
|
92
93
|
rule.validate(5, return_value=True) # -> 5
|
|
93
94
|
rule.validate(-5, return_bool=True) # -> False
|
|
94
|
-
rule.validate(-5) # -> raises
|
|
95
|
+
rule.validate(-5) # -> raises ValidationError
|
|
95
96
|
```
|
|
96
97
|
|
|
97
98
|
### Level 3: Annotation-driven rules
|
|
@@ -104,6 +105,9 @@ typing_rule = IsTyping(dict[str, int])
|
|
|
104
105
|
|
|
105
106
|
typing_rule.is_valid({"apples": 5, "oranges": 10}) # -> True
|
|
106
107
|
typing_rule.is_valid({"apples": "5"}) # -> False
|
|
108
|
+
|
|
109
|
+
# A failing entry is named by its key, not by its position:
|
|
110
|
+
typing_rule.validate({"apples": "5"}, value_name="stock") # fails at stock['apples']
|
|
107
111
|
```
|
|
108
112
|
|
|
109
113
|
### Level 4: Readable descriptions
|
|
@@ -130,13 +134,13 @@ src/simplibs/rules/
|
|
|
130
134
|
├── base_class/ ◄── Abstract base class Rule & internal helpers (_NotARule)
|
|
131
135
|
│ ├── Rule.py
|
|
132
136
|
│ └── _NotARule.py
|
|
133
|
-
├── containers/ ◄── Rule combinators (AllOf, AnyOf, Not, NoneOf, ForEach, Compose, Described)
|
|
137
|
+
├── containers/ ◄── Rule combinators (AllOf, AnyOf, Not, NoneOf, ForEach, ForEachKey, ForEachValue, Compose, Described)
|
|
134
138
|
├── predicates/ ◄── Single-purpose predicate rules
|
|
135
139
|
│ ├── arithmetic/ ◄── CloseTo, DivisibleBy, HasRemainder
|
|
136
140
|
│ ├── checkers/ ◄── IsEmpty, NotEmpty, IsNone, IsTrue, IsFalse
|
|
137
141
|
│ ├── collections/ ◄── IsContainer, HasItem, HasKey, HasKeys, AllUnique, IsSubsetOf, IsSupersetOf
|
|
138
142
|
│ ├── comparisons/ ◄── Equals, NotEquals, GreaterThan, GreaterOrEqual, LessThan, LessOrEqual, InRange
|
|
139
|
-
│ ├── introspection/ ◄── IsInstance, IsType, IsSubclass, IsDataclass, IsCallable, IsHashable, IsIterable, HasAttribute, HasLength
|
|
143
|
+
│ ├── introspection/ ◄── IsInstance, IsType, IsSubclass, IsDataclass, IsCallable, IsHashable, IsIterable, IsReiterable, HasAttribute, HasLength
|
|
140
144
|
│ ├── logic/ ◄── Is, IsNot, IsIn, NotIn, UserRule
|
|
141
145
|
│ ├── numeric/ ◄── IsBool, IsInteger, IsFloat, IsDecimal, IsNumber, IsPrimitiveNumber, IsZero, IsNan, IsInfinity, IsPi, IsEven, IsOdd, IsFinite
|
|
142
146
|
│ ├── strings/ ◄── IsString, Contains, IsSubstringOf, StartsWith, EndsWith, Regex, IsBlank, NotBlank, IsAlnum, IsAlpha, IsAscii, IsDigitString, IsLowercase, IsTitlecase, IsUppercase, IsIdentifier, IsPrintable, IsWhitespace
|
|
@@ -229,15 +233,17 @@ Both are fully interchangeable.
|
|
|
229
233
|
|
|
230
234
|
### `containers/` — Composing other rules
|
|
231
235
|
|
|
232
|
-
| Class
|
|
233
|
-
|
|
234
|
-
| `AllOf`
|
|
235
|
-
| `AnyOf`
|
|
236
|
-
| `Compose`
|
|
237
|
-
| `ForEach`
|
|
238
|
-
| `
|
|
239
|
-
| `
|
|
240
|
-
| `
|
|
236
|
+
| Class | Shortcut | Description / Parameters |
|
|
237
|
+
|----------------|------------------|---------------------------------------------------------------------------------------|
|
|
238
|
+
| `AllOf` | `all_of` | Logical AND across multiple rules (`*rules`). Behind `&`. |
|
|
239
|
+
| `AnyOf` | `any_of` | Logical OR across multiple rules (`*rules`). Behind `\|`. |
|
|
240
|
+
| `Compose` | `compose` | Transforms value before checking (`transformer, validator`). |
|
|
241
|
+
| `ForEach` | `for_each` | Validates every item in an iterable (`rule`). |
|
|
242
|
+
| `ForEachKey` | `for_each_key` | Validates every key of a mapping (`rule`). |
|
|
243
|
+
| `ForEachValue` | `for_each_value` | Validates every value of a mapping; a failing one is named by its key (`rule`). |
|
|
244
|
+
| `NoneOf` | `none_of` | Value must satisfy none of the given rules (`*rules`). |
|
|
245
|
+
| `Not` | `negate` | Logical NOT for a single rule (`rule`). Behind `~`. |
|
|
246
|
+
| `Described` | - | Behaves like the wrapped rule, but describes itself with a fixed text (`rule, text`). |
|
|
241
247
|
|
|
242
248
|
➡️ [README_RULE_CONTAINERS](https://github.com/simplibs/simplibs-rules/blob/main/docs/rules/README_RULE_CONTAINERS.md)
|
|
243
249
|
|
|
@@ -258,7 +264,7 @@ Both are fully interchangeable.
|
|
|
258
264
|
[README_RULE_PREDICATE_COMPARISONS](https://github.com/simplibs/simplibs-rules/blob/main/docs/rules/README_RULE_PREDICATE_COMPARISONS.md)
|
|
259
265
|
|
|
260
266
|
* **`introspection/`**: `IsInstance`, `IsType`, `IsSubclass`, `IsDataclass`,
|
|
261
|
-
`IsCallable`, `IsHashable`, `IsIterable`, `HasAttribute`, `HasLength`
|
|
267
|
+
`IsCallable`, `IsHashable`, `IsIterable`, `IsReiterable`, `HasAttribute`, `HasLength`
|
|
262
268
|
[README_RULE_PREDICATE_INTROSPECTION](https://github.com/simplibs/simplibs-rules/blob/main/docs/rules/README_RULE_PREDICATE_INTROSPECTION.md)
|
|
263
269
|
|
|
264
270
|
* **`logic/`**: `Is`, `IsNot`, `IsIn`, `NotIn`, `UserRule`
|
|
@@ -285,6 +291,13 @@ Both are fully interchangeable.
|
|
|
285
291
|
int] | None`, `Literal[...]`, `Callable[...]`, ...) into a composed `Rule` tree — the
|
|
286
292
|
mechanism that also powers `simplibs-validate`'s `validate_call`/`validate_dataclass`.
|
|
287
293
|
|
|
294
|
+
> **One-shot iterators:** `Iterable[T]` checks the value item by item, which would consume
|
|
295
|
+
> a generator, so a generator (or any other one-shot iterator) is **rejected** with a clear
|
|
296
|
+
> error instead of being passed on exhausted — see
|
|
297
|
+
> [`IsReiterable`](https://github.com/simplibs/simplibs-rules/blob/main/docs/rules/README_RULE_PREDICATE_INTROSPECTION.md#isreiterable).
|
|
298
|
+
> Plain `Iterable` still accepts generators; use a `list`/`tuple`/`set` (or `Collection[T]`)
|
|
299
|
+
> to have items checked.
|
|
300
|
+
|
|
288
301
|
➡️ [README_RULE_TYPING](https://github.com/simplibs/simplibs-rules/blob/main/docs/rules/README_RULE_TYPING.md) — the public `IsTyping`/`build_typing_rule` entry points
|
|
289
302
|
➡️ [README_RULE_TYPING_BUILDERS](https://github.com/simplibs/simplibs-rules/blob/main/docs/rules/README_RULE_TYPING_BUILDERS.md) — the internal per-construct decomposition engine
|
|
290
303
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
[build-system]
|
|
2
|
-
requires = ["setuptools>=
|
|
2
|
+
requires = ["setuptools>=77.0.3"]
|
|
3
3
|
build-backend = "setuptools.build_meta"
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "simplibs-rules"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.5.0"
|
|
8
8
|
description = "Composable, explicit validation rules — pure predicates, zero transformation."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -32,7 +32,7 @@ classifiers = [
|
|
|
32
32
|
"Topic :: Software Development :: Testing",
|
|
33
33
|
]
|
|
34
34
|
dependencies = [
|
|
35
|
-
"simplibs-exception>=1.1.
|
|
35
|
+
"simplibs-exception>=1.1.4",
|
|
36
36
|
"simplibs-sentinels>=0.2.0",
|
|
37
37
|
]
|
|
38
38
|
|
|
@@ -48,13 +48,26 @@ Changelog = "https://github.com/simplibs/simplibs-rules/blob/main/CHANGELOG.md"
|
|
|
48
48
|
|
|
49
49
|
[project.optional-dependencies]
|
|
50
50
|
dev = [
|
|
51
|
-
"pytest>=
|
|
51
|
+
"pytest>=9.0",
|
|
52
|
+
"pytest-cov>=5.0",
|
|
53
|
+
|
|
52
54
|
]
|
|
53
55
|
|
|
54
56
|
[tool.pytest.ini_options]
|
|
55
57
|
testpaths = ["tests"]
|
|
56
58
|
pythonpath = ["src"]
|
|
57
|
-
addopts = "-v"
|
|
59
|
+
addopts = "-v -rs" # -rs lists every skipped test with its reason
|
|
60
|
+
|
|
61
|
+
[tool.coverage.run]
|
|
62
|
+
branch = true
|
|
63
|
+
source = ["simplibs.rules"]
|
|
64
|
+
|
|
65
|
+
[tool.coverage.report]
|
|
66
|
+
show_missing = true
|
|
67
|
+
skip_empty = true
|
|
58
68
|
|
|
59
69
|
[tool.setuptools.packages.find]
|
|
60
|
-
where = ["src"]
|
|
70
|
+
where = ["src"]
|
|
71
|
+
|
|
72
|
+
[tool.setuptools.package-data]
|
|
73
|
+
"simplibs.rules" = ["py.typed"] # without this section py.typed is NOT in the wheel
|
|
@@ -9,6 +9,8 @@ from .containers import (
|
|
|
9
9
|
AnyOf,
|
|
10
10
|
Compose,
|
|
11
11
|
ForEach,
|
|
12
|
+
ForEachKey,
|
|
13
|
+
ForEachValue,
|
|
12
14
|
NoneOf,
|
|
13
15
|
Not,
|
|
14
16
|
Described
|
|
@@ -61,6 +63,7 @@ from .predicates.introspection import (
|
|
|
61
63
|
IsHashable,
|
|
62
64
|
IsInstance,
|
|
63
65
|
IsIterable,
|
|
66
|
+
IsReiterable,
|
|
64
67
|
IsSubclass,
|
|
65
68
|
IsType,
|
|
66
69
|
)
|
|
@@ -145,6 +148,8 @@ all_of = AllOf # *rules
|
|
|
145
148
|
any_of = AnyOf # *rules
|
|
146
149
|
compose = Compose # transformer, validator
|
|
147
150
|
for_each = ForEach # rule
|
|
151
|
+
for_each_key = ForEachKey # rule
|
|
152
|
+
for_each_value = ForEachValue # rule
|
|
148
153
|
none_of = NoneOf # *rules
|
|
149
154
|
negate = Not # rule
|
|
150
155
|
described = Described # rule, text
|
|
@@ -197,6 +202,7 @@ is_dataclass = IsDataclass()
|
|
|
197
202
|
is_hashable = IsHashable()
|
|
198
203
|
is_instance = IsInstance # *types
|
|
199
204
|
is_iterable = IsIterable()
|
|
205
|
+
is_reiterable = IsReiterable()
|
|
200
206
|
is_subclass = IsSubclass # *types
|
|
201
207
|
is_type = IsType()
|
|
202
208
|
|
|
@@ -269,6 +275,8 @@ rule_class = SimpleNamespace(
|
|
|
269
275
|
AnyOf=AnyOf,
|
|
270
276
|
Compose=Compose,
|
|
271
277
|
ForEach=ForEach,
|
|
278
|
+
ForEachKey=ForEachKey,
|
|
279
|
+
ForEachValue=ForEachValue,
|
|
272
280
|
NoneOf=NoneOf,
|
|
273
281
|
Not=Not,
|
|
274
282
|
Described=Described,
|
|
@@ -311,6 +319,7 @@ rule_class = SimpleNamespace(
|
|
|
311
319
|
IsHashable=IsHashable,
|
|
312
320
|
IsInstance=IsInstance,
|
|
313
321
|
IsIterable=IsIterable,
|
|
322
|
+
IsReiterable=IsReiterable,
|
|
314
323
|
IsSubclass=IsSubclass,
|
|
315
324
|
IsType=IsType,
|
|
316
325
|
|
|
@@ -374,6 +383,8 @@ rules = SimpleNamespace(
|
|
|
374
383
|
any_of=any_of,
|
|
375
384
|
compose=compose,
|
|
376
385
|
for_each=for_each,
|
|
386
|
+
for_each_key=for_each_key,
|
|
387
|
+
for_each_value=for_each_value,
|
|
377
388
|
none_of=none_of,
|
|
378
389
|
negate=negate,
|
|
379
390
|
described=described,
|
|
@@ -423,6 +434,7 @@ rules = SimpleNamespace(
|
|
|
423
434
|
is_hashable=is_hashable,
|
|
424
435
|
is_instance=is_instance,
|
|
425
436
|
is_iterable=is_iterable,
|
|
437
|
+
is_reiterable=is_reiterable,
|
|
426
438
|
is_subclass=is_subclass,
|
|
427
439
|
is_type=is_type,
|
|
428
440
|
|
|
@@ -493,6 +505,8 @@ __all__ = [
|
|
|
493
505
|
"AnyOf",
|
|
494
506
|
"Compose",
|
|
495
507
|
"ForEach",
|
|
508
|
+
"ForEachKey",
|
|
509
|
+
"ForEachValue",
|
|
496
510
|
"NoneOf",
|
|
497
511
|
"Not",
|
|
498
512
|
"Described",
|
|
@@ -535,6 +549,7 @@ __all__ = [
|
|
|
535
549
|
"IsHashable",
|
|
536
550
|
"IsInstance",
|
|
537
551
|
"IsIterable",
|
|
552
|
+
"IsReiterable",
|
|
538
553
|
"IsSubclass",
|
|
539
554
|
"IsType",
|
|
540
555
|
|
|
@@ -592,6 +607,8 @@ __all__ = [
|
|
|
592
607
|
"any_of",
|
|
593
608
|
"compose",
|
|
594
609
|
"for_each",
|
|
610
|
+
"for_each_key",
|
|
611
|
+
"for_each_value",
|
|
595
612
|
"none_of",
|
|
596
613
|
"negate",
|
|
597
614
|
"described",
|
|
@@ -631,6 +648,7 @@ __all__ = [
|
|
|
631
648
|
"is_hashable",
|
|
632
649
|
"is_instance",
|
|
633
650
|
"is_iterable",
|
|
651
|
+
"is_reiterable",
|
|
634
652
|
"is_subclass",
|
|
635
653
|
"is_type",
|
|
636
654
|
"same_as",
|
|
@@ -676,7 +694,6 @@ __all__ = [
|
|
|
676
694
|
"always_false",
|
|
677
695
|
"always_true",
|
|
678
696
|
"is_any",
|
|
679
|
-
"is_typing",
|
|
680
697
|
]
|
|
681
698
|
|
|
682
699
|
|
|
@@ -815,15 +832,17 @@ are compound names rather than the keywords themselves.
|
|
|
815
832
|
|
|
816
833
|
### `containers/`
|
|
817
834
|
|
|
818
|
-
| Shortcut
|
|
819
|
-
|
|
820
|
-
| `all_of`
|
|
821
|
-
| `any_of`
|
|
822
|
-
| `compose`
|
|
823
|
-
| `for_each`
|
|
824
|
-
| `
|
|
825
|
-
| `
|
|
826
|
-
| `
|
|
835
|
+
| Shortcut | Parameters | Logic |
|
|
836
|
+
|------------------|--------------------------|--------------------------------------------------|
|
|
837
|
+
| `all_of` | `*rules` | All rules must pass. |
|
|
838
|
+
| `any_of` | `*rules` | At least one rule must pass. |
|
|
839
|
+
| `compose` | `transformer, validator` | Validate the transformed value. |
|
|
840
|
+
| `for_each` | `rule` | The rule must pass for every item. |
|
|
841
|
+
| `for_each_key` | `rule` | The rule must pass for every key of a mapping. |
|
|
842
|
+
| `for_each_value` | `rule` | The rule must pass for every value of a mapping. |
|
|
843
|
+
| `none_of` | `*rules` | No rule may pass. |
|
|
844
|
+
| `negate` | `rule` | The rule must fail. |
|
|
845
|
+
| `described` | `rule`, `text` | Wrap the rule with a fixed description. |
|
|
827
846
|
|
|
828
847
|
|
|
829
848
|
### `predicates/arithmetic/`
|
|
@@ -889,6 +908,7 @@ are compound names rather than the keywords themselves.
|
|
|
889
908
|
| `is_hashable` | — | Value is hashable. |
|
|
890
909
|
| `is_instance` | `*types` | `isinstance(value, types)` |
|
|
891
910
|
| `is_iterable` | — | Value is iterable. |
|
|
911
|
+
| `is_reiterable` | — | Value is iterable, not a one-shot iterator. |
|
|
892
912
|
| `is_subclass` | `*types` | Value is a subclass of the specified types. |
|
|
893
913
|
| `is_type` | — | Value is a type object. |
|
|
894
914
|
|
|
@@ -141,4 +141,23 @@ every individual element within an input iterable container.
|
|
|
141
141
|
* **Failure Cards Unchanged:**
|
|
142
142
|
`build_exception` still points at the exact failing item; only the summary
|
|
143
143
|
text used by other containers comes from `describe()`.
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## 4. One-Shot Iterators Are Consumed
|
|
148
|
+
|
|
149
|
+
`ForEach` walks the value with `iter(value)`, so a generator or any other iterator is
|
|
150
|
+
exhausted by validation (and `build_exception` then re-reads an already consumed value).
|
|
151
|
+
This is inherent to checking items. Callers that must keep such a value intact put
|
|
152
|
+
`IsReiterable` in front (`IsReiterable() & ForEach(rule)`); `Iterable[T]` does this
|
|
153
|
+
automatically in the typing layer.
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## 5. Mappings
|
|
158
|
+
|
|
159
|
+
Over a mapping `ForEach` walks its keys, by the iteration contract of Python, and
|
|
160
|
+
labels a failing item by its position (`opts[1]`), not by its key. To check the keys
|
|
161
|
+
or the values of a mapping, and to have a failing entry named by its key, use
|
|
162
|
+
`ForEachKey` (`opts[key 'zz']`) and `ForEachValue` (`opts['b']`).
|
|
144
163
|
"""
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
from collections.abc import Mapping
|
|
2
|
+
from typing import Any, Callable
|
|
3
|
+
from simplibs.exception import ValidationError
|
|
4
|
+
# Outers
|
|
5
|
+
from ..base_class import Rule
|
|
6
|
+
from ..predicates.introspection import IsInstance
|
|
7
|
+
# Inners
|
|
8
|
+
from ._helpers import as_predicate, build_child_exception, describe_rule, format_key_label
|
|
9
|
+
from .AllOf import AllOf
|
|
10
|
+
from .AnyOf import AnyOf
|
|
11
|
+
from .Compose import Compose
|
|
12
|
+
from ._init_validators import raise_rule_param_not_callable
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ForEachKey(Rule):
|
|
16
|
+
"""Every key of a mapping must satisfy the given rule.
|
|
17
|
+
|
|
18
|
+
Rule:
|
|
19
|
+
all(rule(key) for key in value.keys())
|
|
20
|
+
|
|
21
|
+
Example:
|
|
22
|
+
validate(options, ForEachKey(IsString()))
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
__slots__ = ("rule",)
|
|
26
|
+
|
|
27
|
+
# ----------------------------------------------------------------------
|
|
28
|
+
# Constructor initialization
|
|
29
|
+
# ----------------------------------------------------------------------
|
|
30
|
+
def __init__(self, rule: Rule | Callable[[Any], bool]) -> None:
|
|
31
|
+
|
|
32
|
+
# 1. Parameter validation
|
|
33
|
+
if not callable(rule):
|
|
34
|
+
raise_rule_param_not_callable("ForEachKey", rule)
|
|
35
|
+
|
|
36
|
+
# 2. Parameter assignment
|
|
37
|
+
self.rule = rule
|
|
38
|
+
|
|
39
|
+
# ----------------------------------------------------------------------
|
|
40
|
+
# Rule definition
|
|
41
|
+
# ----------------------------------------------------------------------
|
|
42
|
+
def is_valid(self, value: Any) -> bool:
|
|
43
|
+
|
|
44
|
+
# 1. Only a mapping has keys
|
|
45
|
+
if not isinstance(value, Mapping):
|
|
46
|
+
return False
|
|
47
|
+
|
|
48
|
+
# 2. Evaluate the rule for every key
|
|
49
|
+
predicate = as_predicate(self.rule)
|
|
50
|
+
return all(predicate(key) for key in value.keys())
|
|
51
|
+
|
|
52
|
+
# ----------------------------------------------------------------------
|
|
53
|
+
# Description definition
|
|
54
|
+
# ----------------------------------------------------------------------
|
|
55
|
+
def describe(self) -> str:
|
|
56
|
+
|
|
57
|
+
# 1. Compound operands need parentheses: each key: (a | b)
|
|
58
|
+
return f"each key: {describe_rule(self.rule, parenthesize=(AllOf, AnyOf, Compose))}"
|
|
59
|
+
|
|
60
|
+
# ----------------------------------------------------------------------
|
|
61
|
+
# Exception definition
|
|
62
|
+
# ----------------------------------------------------------------------
|
|
63
|
+
def build_exception(
|
|
64
|
+
self,
|
|
65
|
+
value: Any,
|
|
66
|
+
value_name: str | None = None,
|
|
67
|
+
context: str | None = None,
|
|
68
|
+
) -> Exception:
|
|
69
|
+
|
|
70
|
+
# 1. A value that is not a mapping fails on the mapping check
|
|
71
|
+
if not isinstance(value, Mapping):
|
|
72
|
+
return IsInstance(Mapping).build_exception(value, value_name, context)
|
|
73
|
+
|
|
74
|
+
# 2. Find the first key that fails the rule and build a child exception
|
|
75
|
+
predicate = as_predicate(self.rule)
|
|
76
|
+
for key in value.keys():
|
|
77
|
+
if not predicate(key):
|
|
78
|
+
return build_child_exception(
|
|
79
|
+
self.rule,
|
|
80
|
+
key,
|
|
81
|
+
format_key_label(key, value_name),
|
|
82
|
+
context,
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
# 3. Fallback (build exception if all keys unexpectedly passed)
|
|
86
|
+
return ValidationError(
|
|
87
|
+
error_name="FOR_EACH_KEY_UNREACHABLE_ERROR",
|
|
88
|
+
label=value_name,
|
|
89
|
+
expected="mapping with all keys passing the rule",
|
|
90
|
+
value=value,
|
|
91
|
+
problem="All keys unexpectedly passed during error construction.",
|
|
92
|
+
context=context,
|
|
93
|
+
how_to_fix=("Check mapping keys state.",),
|
|
94
|
+
exception=RuntimeError,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
_DESIGN_NOTES = """
|
|
99
|
+
# ForEachKey — Mapping Key Validation Container Rule
|
|
100
|
+
|
|
101
|
+
## Purpose
|
|
102
|
+
The `ForEachKey` rule applies a target validation rule or callable predicate
|
|
103
|
+
to every key of a mapping.
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## 1. Why a Rule of Its Own
|
|
108
|
+
|
|
109
|
+
* **`ForEach` Cannot Say Which Entry Failed:**
|
|
110
|
+
It knows only the position of an item (`opts[1]`), not what the entry is
|
|
111
|
+
called. For a mapping the name is what a person looks for.
|
|
112
|
+
* **`Compose(keys, ForEach(...))` Throws the Mapping Away:**
|
|
113
|
+
The extraction step hands `ForEach` a bare view, so the information about
|
|
114
|
+
the entry is gone before the exception is built. A rule that receives the
|
|
115
|
+
mapping itself keeps it until the end.
|
|
116
|
+
* **`ForEach` Is Not Changed:**
|
|
117
|
+
Over a mapping it walks the keys by the iteration contract of Python;
|
|
118
|
+
changing that would silently change every existing use.
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## 2. Execution Rationale
|
|
123
|
+
|
|
124
|
+
* **Constructor Safety Guard:**
|
|
125
|
+
Ensures the inner `rule` is either an instance of `Rule` or a callable
|
|
126
|
+
object (`raise_rule_param_not_callable`).
|
|
127
|
+
* **Mapping Check:**
|
|
128
|
+
`is_valid` returns `False` for anything that is not a `collections.abc.Mapping`.
|
|
129
|
+
* **Non-mapping Exception Delegation:**
|
|
130
|
+
`build_exception` hands a non-mapping to `IsInstance(Mapping)`, so the card
|
|
131
|
+
says what was expected instead of inventing a failing key.
|
|
132
|
+
* **Empty Mapping:**
|
|
133
|
+
Passes (`all()` over nothing is true), same as `ForEach` over an empty list.
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## 3. Exception Card Design
|
|
138
|
+
|
|
139
|
+
* **Key Label:**
|
|
140
|
+
The failing key is named through `format_key_label` — `opts[key 'zz']`, or
|
|
141
|
+
`[key 'zz']` without a name. The word `key` keeps it apart from the label of
|
|
142
|
+
a value (`opts['zz']`).
|
|
143
|
+
* **Transparent Sub-rule Delegation:**
|
|
144
|
+
The card is the exact exception of the sub-rule for the failing key; its
|
|
145
|
+
`value` is the key, not the whole mapping.
|
|
146
|
+
* **Unreachable Fallback:**
|
|
147
|
+
`FOR_EACH_KEY_UNREACHABLE_ERROR` when no key fails during error construction.
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## 4. Description
|
|
152
|
+
|
|
153
|
+
* **Prefix Form:**
|
|
154
|
+
`describe()` returns "each key: <rule>" ("each key: str").
|
|
155
|
+
* **Precedence:**
|
|
156
|
+
A compound operand (`AllOf`, `AnyOf`, `Compose`) is wrapped in parentheses
|
|
157
|
+
("each key: (a | b)").
|
|
158
|
+
"""
|