simplibs-rules 0.3.0__tar.gz → 0.4.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.
Files changed (162) hide show
  1. {simplibs_rules-0.3.0/src/simplibs_rules.egg-info → simplibs_rules-0.4.0}/PKG-INFO +11 -4
  2. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/README.md +10 -3
  3. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/pyproject.toml +1 -1
  4. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/__init__.py +7 -0
  5. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/containers/ForEach.py +10 -0
  6. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/collections/AllUnique.py +43 -9
  7. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/collections/IsSubsetOf.py +42 -8
  8. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/collections/IsSupersetOf.py +42 -8
  9. simplibs_rules-0.4.0/src/simplibs/rules/predicates/introspection/IsReiterable.py +133 -0
  10. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/introspection/__init__.py +14 -12
  11. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/typing/_builders/build_elements_rule.py +41 -4
  12. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0/src/simplibs_rules.egg-info}/PKG-INFO +11 -4
  13. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs_rules.egg-info/SOURCES.txt +1 -0
  14. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/LICENSE +0 -0
  15. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/setup.cfg +0 -0
  16. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/base_class/Rule.py +0 -0
  17. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/base_class/_NotARule.py +0 -0
  18. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/base_class/__init__.py +0 -0
  19. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/containers/AllOf.py +0 -0
  20. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/containers/AnyOf.py +0 -0
  21. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/containers/Compose.py +0 -0
  22. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/containers/Described.py +0 -0
  23. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/containers/NoneOf.py +0 -0
  24. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/containers/Not.py +0 -0
  25. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/containers/__init__.py +0 -0
  26. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/containers/_helpers/__init__.py +0 -0
  27. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/containers/_helpers/as_predicate.py +0 -0
  28. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/containers/_helpers/build_child_exception.py +0 -0
  29. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/containers/_helpers/describe_rule.py +0 -0
  30. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/containers/_helpers/validations/__init__.py +0 -0
  31. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/containers/_helpers/validations/raise_invalid_predicate.py +0 -0
  32. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/containers/_init_validators/__init__.py +0 -0
  33. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/containers/_init_validators/raise_container_param_not_type_error.py +0 -0
  34. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/containers/_init_validators/raise_requires_at_least_one_rule_error.py +0 -0
  35. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/containers/_init_validators/raise_rule_param_not_callable.py +0 -0
  36. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/containers/_init_validators/validate_compose_param_is_callable.py +0 -0
  37. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/__init__.py +0 -0
  38. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/_helpers/__init__.py +0 -0
  39. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/_helpers/accepts_one_positional_argument.py +0 -0
  40. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/_helpers/format_container.py +0 -0
  41. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/_init_validators/__init__.py +0 -0
  42. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/_init_validators/rule_errors/__init__.py +0 -0
  43. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/_init_validators/rule_errors/raise_has_length_param_conflict_error.py +0 -0
  44. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/_init_validators/rule_errors/raise_regex_param_invalid_pattern_error.py +0 -0
  45. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/_init_validators/rule_errors/raise_user_rule_param_wrong_arity.py +0 -0
  46. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/_init_validators/shared_errors/__init__.py +0 -0
  47. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/_init_validators/shared_errors/raise_param_min_max_bounds_inverted_error.py +0 -0
  48. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/_init_validators/shared_errors/raise_param_min_max_incomparable_error.py +0 -0
  49. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/_init_validators/shared_errors/raise_param_missing_error.py +0 -0
  50. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/_init_validators/shared_errors/raise_param_not_callable_error.py +0 -0
  51. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/_init_validators/shared_errors/raise_param_not_container_error.py +0 -0
  52. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/_init_validators/shared_errors/raise_param_not_non_negative_integer_error.py +0 -0
  53. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/_init_validators/shared_errors/raise_param_not_string_error.py +0 -0
  54. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/_init_validators/shared_errors/raise_param_not_type_error.py +0 -0
  55. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/_init_validators/shared_validators/__init__.py +0 -0
  56. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/_init_validators/shared_validators/validate_param_is_integer.py +0 -0
  57. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/_init_validators/shared_validators/validate_param_is_not_zero.py +0 -0
  58. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/_init_validators/shared_validators/validate_param_is_primitive_number.py +0 -0
  59. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/_init_validators/shared_validators/validate_param_remainder_in_range.py +0 -0
  60. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/arithmetic/CloseTo.py +0 -0
  61. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/arithmetic/DivisibleBy.py +0 -0
  62. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/arithmetic/HasRemainder.py +0 -0
  63. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/arithmetic/__init__.py +0 -0
  64. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/checkers/IsEmpty.py +0 -0
  65. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/checkers/IsFalse.py +0 -0
  66. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/checkers/IsNone.py +0 -0
  67. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/checkers/IsTrue.py +0 -0
  68. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/checkers/NotEmpty.py +0 -0
  69. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/checkers/__init__.py +0 -0
  70. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/collections/HasItem.py +0 -0
  71. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/collections/HasKey.py +0 -0
  72. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/collections/HasKeys.py +0 -0
  73. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/collections/IsContainer.py +0 -0
  74. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/collections/__init__.py +0 -0
  75. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/comparisons/Equals.py +0 -0
  76. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/comparisons/GreaterOrEqual.py +0 -0
  77. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/comparisons/GreaterThan.py +0 -0
  78. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/comparisons/InRange.py +0 -0
  79. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/comparisons/LessOrEqual.py +0 -0
  80. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/comparisons/LessThan.py +0 -0
  81. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/comparisons/NotEquals.py +0 -0
  82. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/comparisons/__init__.py +0 -0
  83. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/introspection/HasAttribute.py +0 -0
  84. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/introspection/HasLength.py +0 -0
  85. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/introspection/IsCallable.py +0 -0
  86. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/introspection/IsDataclass.py +0 -0
  87. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/introspection/IsHashable.py +0 -0
  88. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/introspection/IsInstance.py +0 -0
  89. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/introspection/IsIterable.py +0 -0
  90. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/introspection/IsSubclass.py +0 -0
  91. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/introspection/IsType.py +0 -0
  92. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/logic/Is.py +0 -0
  93. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/logic/IsIn.py +0 -0
  94. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/logic/IsNot.py +0 -0
  95. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/logic/NotIn.py +0 -0
  96. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/logic/UserRule.py +0 -0
  97. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/logic/__init__.py +0 -0
  98. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/numeric/IsBool.py +0 -0
  99. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/numeric/IsDecimal.py +0 -0
  100. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/numeric/IsEven.py +0 -0
  101. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/numeric/IsFinite.py +0 -0
  102. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/numeric/IsFloat.py +0 -0
  103. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/numeric/IsInfinity.py +0 -0
  104. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/numeric/IsInteger.py +0 -0
  105. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/numeric/IsNan.py +0 -0
  106. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/numeric/IsNumber.py +0 -0
  107. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/numeric/IsOdd.py +0 -0
  108. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/numeric/IsPi.py +0 -0
  109. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/numeric/IsPrimitiveNumber.py +0 -0
  110. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/numeric/IsZero.py +0 -0
  111. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/numeric/__init__.py +0 -0
  112. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/strings/Contains.py +0 -0
  113. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/strings/EndsWith.py +0 -0
  114. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/strings/IsAlnum.py +0 -0
  115. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/strings/IsAlpha.py +0 -0
  116. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/strings/IsAscii.py +0 -0
  117. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/strings/IsBlank.py +0 -0
  118. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/strings/IsDigitString.py +0 -0
  119. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/strings/IsIdentifier.py +0 -0
  120. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/strings/IsLowercase.py +0 -0
  121. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/strings/IsPrintable.py +0 -0
  122. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/strings/IsString.py +0 -0
  123. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/strings/IsSubstringOf.py +0 -0
  124. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/strings/IsTitlecase.py +0 -0
  125. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/strings/IsUppercase.py +0 -0
  126. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/strings/IsWhitespace.py +0 -0
  127. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/strings/NotBlank.py +0 -0
  128. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/strings/Regex.py +0 -0
  129. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/strings/StartsWith.py +0 -0
  130. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/strings/__init__.py +0 -0
  131. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/typing/IsAny.py +0 -0
  132. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/typing/IsTyping.py +0 -0
  133. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/typing/__init__.py +0 -0
  134. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/typing/_builders/ORIGIN_TABLE.py +0 -0
  135. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/typing/_builders/__init__.py +0 -0
  136. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/typing/_builders/build_annotated_rule.py +0 -0
  137. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/typing/_builders/build_any_of_rule.py +0 -0
  138. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/typing/_builders/build_callable_rule.py +0 -0
  139. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/typing/_builders/build_key_value_rule.py +0 -0
  140. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/typing/_builders/build_literal_rule.py +0 -0
  141. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/typing/_builders/build_tuple_rule.py +0 -0
  142. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/typing/_builders/build_type_rule.py +0 -0
  143. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/typing/_helpers/__init__.py +0 -0
  144. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/typing/_helpers/format_annotation.py +0 -0
  145. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/typing/_validations/__init__.py +0 -0
  146. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/typing/_validations/raise_unsupported_annotation_error.py +0 -0
  147. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/typing/build_typing_rule.py +0 -0
  148. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/typing/tools/__init__.py +0 -0
  149. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/typing/tools/get_supported_origins.py +0 -0
  150. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/predicates/typing/tools/is_supported_annotation.py +0 -0
  151. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/testing/__init__.py +0 -0
  152. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/testing/assert_rule_contract.py +0 -0
  153. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/testing/asserts/__init__.py +0 -0
  154. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/testing/asserts/assert_rule_build_exception.py +0 -0
  155. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/testing/asserts/assert_rule_describe.py +0 -0
  156. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/testing/asserts/assert_rule_is_valid.py +0 -0
  157. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/testing/asserts/assert_rule_param_error.py +0 -0
  158. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/testing/asserts/assert_rule_slots.py +0 -0
  159. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs/rules/testing/asserts/assert_rule_validate.py +0 -0
  160. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs_rules.egg-info/dependency_links.txt +0 -0
  161. {simplibs_rules-0.3.0 → simplibs_rules-0.4.0}/src/simplibs_rules.egg-info/requires.txt +0 -0
  162. {simplibs_rules-0.3.0 → simplibs_rules-0.4.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.0
3
+ Version: 0.4.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
@@ -119,7 +119,7 @@ rule = is_integer & greater_than(0)
119
119
  rule.validate(5) # -> True
120
120
  rule.validate(5, return_value=True) # -> 5
121
121
  rule.validate(-5, return_bool=True) # -> False
122
- rule.validate(-5) # -> raises ValidateError
122
+ rule.validate(-5) # -> raises ValidationError
123
123
  ```
124
124
 
125
125
  ### Level 3: Annotation-driven rules
@@ -164,7 +164,7 @@ src/simplibs/rules/
164
164
  │ ├── checkers/ ◄── IsEmpty, NotEmpty, IsNone, IsTrue, IsFalse
165
165
  │ ├── collections/ ◄── IsContainer, HasItem, HasKey, HasKeys, AllUnique, IsSubsetOf, IsSupersetOf
166
166
  │ ├── comparisons/ ◄── Equals, NotEquals, GreaterThan, GreaterOrEqual, LessThan, LessOrEqual, InRange
167
- │ ├── introspection/ ◄── IsInstance, IsType, IsSubclass, IsDataclass, IsCallable, IsHashable, IsIterable, HasAttribute, HasLength
167
+ │ ├── introspection/ ◄── IsInstance, IsType, IsSubclass, IsDataclass, IsCallable, IsHashable, IsIterable, IsReiterable, HasAttribute, HasLength
168
168
  │ ├── logic/ ◄── Is, IsNot, IsIn, NotIn, UserRule
169
169
  │ ├── numeric/ ◄── IsBool, IsInteger, IsFloat, IsDecimal, IsNumber, IsPrimitiveNumber, IsZero, IsNan, IsInfinity, IsPi, IsEven, IsOdd, IsFinite
170
170
  │ ├── strings/ ◄── IsString, Contains, IsSubstringOf, StartsWith, EndsWith, Regex, IsBlank, NotBlank, IsAlnum, IsAlpha, IsAscii, IsDigitString, IsLowercase, IsTitlecase, IsUppercase, IsIdentifier, IsPrintable, IsWhitespace
@@ -286,7 +286,7 @@ Both are fully interchangeable.
286
286
  [README_RULE_PREDICATE_COMPARISONS](https://github.com/simplibs/simplibs-rules/blob/main/docs/rules/README_RULE_PREDICATE_COMPARISONS.md)
287
287
 
288
288
  * **`introspection/`**: `IsInstance`, `IsType`, `IsSubclass`, `IsDataclass`,
289
- `IsCallable`, `IsHashable`, `IsIterable`, `HasAttribute`, `HasLength`
289
+ `IsCallable`, `IsHashable`, `IsIterable`, `IsReiterable`, `HasAttribute`, `HasLength`
290
290
  [README_RULE_PREDICATE_INTROSPECTION](https://github.com/simplibs/simplibs-rules/blob/main/docs/rules/README_RULE_PREDICATE_INTROSPECTION.md)
291
291
 
292
292
  * **`logic/`**: `Is`, `IsNot`, `IsIn`, `NotIn`, `UserRule`
@@ -313,6 +313,13 @@ Both are fully interchangeable.
313
313
  int] | None`, `Literal[...]`, `Callable[...]`, ...) into a composed `Rule` tree — the
314
314
  mechanism that also powers `simplibs-validate`'s `validate_call`/`validate_dataclass`.
315
315
 
316
+ > **One-shot iterators:** `Iterable[T]` checks the value item by item, which would consume
317
+ > a generator, so a generator (or any other one-shot iterator) is **rejected** with a clear
318
+ > error instead of being passed on exhausted — see
319
+ > [`IsReiterable`](https://github.com/simplibs/simplibs-rules/blob/main/docs/rules/README_RULE_PREDICATE_INTROSPECTION.md#isreiterable).
320
+ > Plain `Iterable` still accepts generators; use a `list`/`tuple`/`set` (or `Collection[T]`)
321
+ > to have items checked.
322
+
316
323
  ➡️ [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
324
  ➡️ [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
325
 
@@ -91,7 +91,7 @@ rule = is_integer & greater_than(0)
91
91
  rule.validate(5) # -> True
92
92
  rule.validate(5, return_value=True) # -> 5
93
93
  rule.validate(-5, return_bool=True) # -> False
94
- rule.validate(-5) # -> raises ValidateError
94
+ rule.validate(-5) # -> raises ValidationError
95
95
  ```
96
96
 
97
97
  ### Level 3: Annotation-driven rules
@@ -136,7 +136,7 @@ src/simplibs/rules/
136
136
  │ ├── checkers/ ◄── IsEmpty, NotEmpty, IsNone, IsTrue, IsFalse
137
137
  │ ├── collections/ ◄── IsContainer, HasItem, HasKey, HasKeys, AllUnique, IsSubsetOf, IsSupersetOf
138
138
  │ ├── comparisons/ ◄── Equals, NotEquals, GreaterThan, GreaterOrEqual, LessThan, LessOrEqual, InRange
139
- │ ├── introspection/ ◄── IsInstance, IsType, IsSubclass, IsDataclass, IsCallable, IsHashable, IsIterable, HasAttribute, HasLength
139
+ │ ├── introspection/ ◄── IsInstance, IsType, IsSubclass, IsDataclass, IsCallable, IsHashable, IsIterable, IsReiterable, HasAttribute, HasLength
140
140
  │ ├── logic/ ◄── Is, IsNot, IsIn, NotIn, UserRule
141
141
  │ ├── numeric/ ◄── IsBool, IsInteger, IsFloat, IsDecimal, IsNumber, IsPrimitiveNumber, IsZero, IsNan, IsInfinity, IsPi, IsEven, IsOdd, IsFinite
142
142
  │ ├── strings/ ◄── IsString, Contains, IsSubstringOf, StartsWith, EndsWith, Regex, IsBlank, NotBlank, IsAlnum, IsAlpha, IsAscii, IsDigitString, IsLowercase, IsTitlecase, IsUppercase, IsIdentifier, IsPrintable, IsWhitespace
@@ -258,7 +258,7 @@ Both are fully interchangeable.
258
258
  [README_RULE_PREDICATE_COMPARISONS](https://github.com/simplibs/simplibs-rules/blob/main/docs/rules/README_RULE_PREDICATE_COMPARISONS.md)
259
259
 
260
260
  * **`introspection/`**: `IsInstance`, `IsType`, `IsSubclass`, `IsDataclass`,
261
- `IsCallable`, `IsHashable`, `IsIterable`, `HasAttribute`, `HasLength`
261
+ `IsCallable`, `IsHashable`, `IsIterable`, `IsReiterable`, `HasAttribute`, `HasLength`
262
262
  [README_RULE_PREDICATE_INTROSPECTION](https://github.com/simplibs/simplibs-rules/blob/main/docs/rules/README_RULE_PREDICATE_INTROSPECTION.md)
263
263
 
264
264
  * **`logic/`**: `Is`, `IsNot`, `IsIn`, `NotIn`, `UserRule`
@@ -285,6 +285,13 @@ Both are fully interchangeable.
285
285
  int] | None`, `Literal[...]`, `Callable[...]`, ...) into a composed `Rule` tree — the
286
286
  mechanism that also powers `simplibs-validate`'s `validate_call`/`validate_dataclass`.
287
287
 
288
+ > **One-shot iterators:** `Iterable[T]` checks the value item by item, which would consume
289
+ > a generator, so a generator (or any other one-shot iterator) is **rejected** with a clear
290
+ > error instead of being passed on exhausted — see
291
+ > [`IsReiterable`](https://github.com/simplibs/simplibs-rules/blob/main/docs/rules/README_RULE_PREDICATE_INTROSPECTION.md#isreiterable).
292
+ > Plain `Iterable` still accepts generators; use a `list`/`tuple`/`set` (or `Collection[T]`)
293
+ > to have items checked.
294
+
288
295
  ➡️ [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
296
  ➡️ [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
297
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "simplibs-rules"
7
- version = "0.3.0"
7
+ version = "0.4.0"
8
8
  description = "Composable, explicit validation rules — pure predicates, zero transformation."
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -61,6 +61,7 @@ from .predicates.introspection import (
61
61
  IsHashable,
62
62
  IsInstance,
63
63
  IsIterable,
64
+ IsReiterable,
64
65
  IsSubclass,
65
66
  IsType,
66
67
  )
@@ -197,6 +198,7 @@ is_dataclass = IsDataclass()
197
198
  is_hashable = IsHashable()
198
199
  is_instance = IsInstance # *types
199
200
  is_iterable = IsIterable()
201
+ is_reiterable = IsReiterable()
200
202
  is_subclass = IsSubclass # *types
201
203
  is_type = IsType()
202
204
 
@@ -311,6 +313,7 @@ rule_class = SimpleNamespace(
311
313
  IsHashable=IsHashable,
312
314
  IsInstance=IsInstance,
313
315
  IsIterable=IsIterable,
316
+ IsReiterable=IsReiterable,
314
317
  IsSubclass=IsSubclass,
315
318
  IsType=IsType,
316
319
 
@@ -423,6 +426,7 @@ rules = SimpleNamespace(
423
426
  is_hashable=is_hashable,
424
427
  is_instance=is_instance,
425
428
  is_iterable=is_iterable,
429
+ is_reiterable=is_reiterable,
426
430
  is_subclass=is_subclass,
427
431
  is_type=is_type,
428
432
 
@@ -535,6 +539,7 @@ __all__ = [
535
539
  "IsHashable",
536
540
  "IsInstance",
537
541
  "IsIterable",
542
+ "IsReiterable",
538
543
  "IsSubclass",
539
544
  "IsType",
540
545
 
@@ -631,6 +636,7 @@ __all__ = [
631
636
  "is_hashable",
632
637
  "is_instance",
633
638
  "is_iterable",
639
+ "is_reiterable",
634
640
  "is_subclass",
635
641
  "is_type",
636
642
  "same_as",
@@ -889,6 +895,7 @@ are compound names rather than the keywords themselves.
889
895
  | `is_hashable` | — | Value is hashable. |
890
896
  | `is_instance` | `*types` | `isinstance(value, types)` |
891
897
  | `is_iterable` | — | Value is iterable. |
898
+ | `is_reiterable` | — | Value is iterable, not a one-shot iterator. |
892
899
  | `is_subclass` | `*types` | Value is a subclass of the specified types. |
893
900
  | `is_type` | — | Value is a type object. |
894
901
 
@@ -141,4 +141,14 @@ 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.
144
154
  """
@@ -1,3 +1,4 @@
1
+ from collections.abc import Iterable, Iterator
1
2
  from typing import Any
2
3
  from simplibs.exception import ValidationError
3
4
  # Outers
@@ -22,18 +23,22 @@ class AllUnique(Rule):
22
23
  def is_valid(self, value: Any) -> bool:
23
24
 
24
25
  # 1. Handling for when value is not iterable
25
- if not hasattr(value, "__iter__"):
26
+ if not isinstance(value, Iterable):
26
27
  return False
27
28
 
28
- # 2. Convert to a list for repeated inspection
29
+ # 2. A one-shot iterator would be consumed by this check — reject it untouched
30
+ if isinstance(value, Iterator):
31
+ return False
32
+
33
+ # 3. Convert to a list for repeated inspection
29
34
  items = list(value)
30
35
 
31
- # 3. Evaluate item uniqueness
32
- # 3.1 Fast path for hashable items — O(n)
36
+ # 4. Evaluate item uniqueness
37
+ # 4.1 Fast path for hashable items — O(n)
33
38
  try:
34
39
  return len(set(items)) == len(items)
35
40
 
36
- # 3.2 Fallback for unhashable items — O(n^2)
41
+ # 4.2 Fallback for unhashable items — O(n^2)
37
42
  except TypeError:
38
43
  seen: list[Any] = []
39
44
  for item in items:
@@ -62,12 +67,21 @@ class AllUnique(Rule):
62
67
 
63
68
  # 1. Prepare data
64
69
  # 1.1 When value is not iterable
65
- if not hasattr(value, "__iter__"):
70
+ if not isinstance(value, Iterable):
66
71
  problem = f"Value {value!r} of type '{type(value).__name__}' is not iterable."
67
72
  how_to_fix = "Provide an iterable container (e.g., list, tuple, set)."
68
73
  exception_type = TypeError
69
74
 
70
- # 1.2 When value contains duplicates
75
+ # 1.2 When value is a one-shot iterator (validating it would have consumed it)
76
+ elif isinstance(value, Iterator):
77
+ problem = (
78
+ f"Value of type '{type(value).__name__}' is a one-shot iterator: "
79
+ "checking its items would consume it."
80
+ )
81
+ how_to_fix = "Pass a list, tuple or set (e.g. list(value)) instead of the iterator."
82
+ exception_type = TypeError
83
+
84
+ # 1.3 When value contains duplicates
71
85
  else:
72
86
  items = list(value)
73
87
  duplicates: list[Any] = []
@@ -107,8 +121,9 @@ duplicate elements.
107
121
  ## 1. Execution Rationale & Safeguards
108
122
 
109
123
  * **Explicit Interface Guard (`is_valid`):**
110
- Uses explicit `hasattr(value, "__iter__")` check to safely reject
111
- non-iterable objects without catching unrelated runtime errors.
124
+ Uses an explicit `isinstance(value, Iterable)` check to safely reject
125
+ non-iterable objects without catching unrelated runtime errors, and
126
+ rejects one-shot iterators (see section 4).
112
127
  * **Hybrid Uniqueness Inspection:**
113
128
  * Fast-path set inspection (`O(n)`) for hashable elements (integers,
114
129
  strings, tuples).
@@ -117,6 +132,7 @@ duplicate elements.
117
132
  * **Dual Diagnostic Path (`build_exception`):**
118
133
  Uses internal `if/else` branching to assemble:
119
134
  * A `TypeError` when the input is not iterable.
135
+ * A `TypeError` when the input is a one-shot iterator (the check would consume it).
120
136
  * A `ValueError` (`ALL_UNIQUE_ERROR`) when the input contains duplicates,
121
137
  explicitly listing all duplicate items.
122
138
 
@@ -137,4 +153,22 @@ duplicate elements.
137
153
  `describe()` returns "all unique" — what the value must be. A short fragment that containers and
138
154
  the typing layer compose into larger texts ("not ...", "... | ..."); the failure
139
155
  card keeps its own `expected` sentence.
156
+
157
+ ---
158
+
159
+ ## 4. One-Shot Iterators Are Rejected, Not Consumed
160
+
161
+ This rule has to walk the whole value, and walking a generator (or any other
162
+ iterator) consumes it: the caller would get an exhausted iterator back, and
163
+ when the check fails, the diagnostics would re-read the already consumed value
164
+ and report nothing useful (an empty list of items). An iterator therefore
165
+ never reaches the check — `is_valid` returns `False` for it, and
166
+ `build_exception` explains why (`TypeError`, same `error_name` as the other
167
+ failures of this rule). Re-iterable containers (list, tuple, set, dict, range,
168
+ ...) are unaffected.
169
+
170
+ The iterable test is `isinstance(value, Iterable)` rather than
171
+ `hasattr(value, "__iter__")`: `hasattr` is also true for a class object such as
172
+ `list` itself, which `list(value)` then rejects with a `TypeError` raised out of
173
+ `is_valid`. Same reasoning as `IsReiterable` and `Iterable[T]`.
140
174
  """
@@ -1,3 +1,4 @@
1
+ from collections.abc import Iterable, Iterator
1
2
  from typing import Any, Collection
2
3
  from simplibs.exception import ValidationError
3
4
  # Outers
@@ -37,14 +38,18 @@ class IsSubsetOf(Rule):
37
38
  def is_valid(self, value: Any) -> bool:
38
39
 
39
40
  # 1. Handling for when value is not iterable
40
- if not hasattr(value, "__iter__"):
41
+ if not isinstance(value, Iterable):
41
42
  return False
42
43
 
43
- # 2. Evaluate whether the input is a subset of the reference collection
44
+ # 2. A one-shot iterator would be consumed by this check — reject it untouched
45
+ if isinstance(value, Iterator):
46
+ return False
47
+
48
+ # 3. Evaluate whether the input is a subset of the reference collection
44
49
  try:
45
50
  return set(value) <= self.reference
46
51
 
47
- # 3. Fallback for unhashable items
52
+ # 4. Fallback for unhashable items
48
53
  except TypeError:
49
54
  return False
50
55
 
@@ -76,12 +81,21 @@ class IsSubsetOf(Rule):
76
81
 
77
82
  # 1. Prepare data
78
83
  # 1.1 When value is not iterable
79
- if not hasattr(value, "__iter__"):
84
+ if not isinstance(value, Iterable):
80
85
  problem = f"Value {value!r} of type '{type(value).__name__}' is not iterable."
81
86
  how_to_fix = "Provide an iterable container (e.g., list, tuple, set)."
82
87
  exception_type = TypeError
83
88
 
84
- # 1.2 When value contains elements outside the reference (or unhashable elements)
89
+ # 1.2 When value is a one-shot iterator (validating it would have consumed it)
90
+ elif isinstance(value, Iterator):
91
+ problem = (
92
+ f"Value of type '{type(value).__name__}' is a one-shot iterator: "
93
+ "checking its items would consume it."
94
+ )
95
+ how_to_fix = "Pass a list, tuple or set (e.g. list(value)) instead of the iterator."
96
+ exception_type = TypeError
97
+
98
+ # 1.3 When value contains elements outside the reference (or unhashable elements)
85
99
  else:
86
100
  try:
87
101
  extra = set(value) - self.reference
@@ -131,11 +145,13 @@ reference).
131
145
  ordering in Python's native `set.__repr__`, guaranteeing stable exception
132
146
  messages for assertions, unit testing, and logging aggregation.
133
147
  * **Explicit Interface Guard (`is_valid`):**
134
- Uses explicit `hasattr(value, "__iter__")` check to safely reject
135
- non-iterable objects. Catches `TypeError` only for unhashable elements.
148
+ Uses an explicit `isinstance(value, Iterable)` check to safely reject
149
+ non-iterable objects, and rejects one-shot iterators (see section 4).
150
+ Catches `TypeError` only for unhashable elements.
136
151
  * **Dual Diagnostic Path (`build_exception`):**
137
152
  Uses internal `if/else` branching to assemble:
138
153
  * A `TypeError` when the input is not iterable.
154
+ * A `TypeError` when the input is a one-shot iterator (the check would consume it).
139
155
  * A `ValueError` (`IS_SUBSET_OF_ERROR`) when the input contains
140
156
  disallowed items, explicitly displaying extraneous elements
141
157
  (`set(value) - self.reference`).
@@ -159,4 +175,22 @@ reference).
159
175
  characters are abbreviated to "set(size=N)" in the description only, so a
160
176
  large reference never makes a composed text unreadable; the failure card keeps
161
177
  the full list in `expected`, where it is the useful detail.
162
- """
178
+
179
+ ---
180
+
181
+ ## 4. One-Shot Iterators Are Rejected, Not Consumed
182
+
183
+ This rule has to walk the whole value, and walking a generator (or any other
184
+ iterator) consumes it: the caller would get an exhausted iterator back, and
185
+ when the check fails, the diagnostics would re-read the already consumed value
186
+ and report nothing useful (an empty list of items). An iterator therefore
187
+ never reaches the check — `is_valid` returns `False` for it, and
188
+ `build_exception` explains why (`TypeError`, same `error_name` as the other
189
+ failures of this rule). Re-iterable containers (list, tuple, set, dict, range,
190
+ ...) are unaffected.
191
+
192
+ The iterable test is `isinstance(value, Iterable)` rather than
193
+ `hasattr(value, "__iter__")`: `hasattr` is also true for a class object such as
194
+ `list` itself, which `list(value)` then rejects with a `TypeError` raised out of
195
+ `is_valid`. Same reasoning as `IsReiterable` and `Iterable[T]`.
196
+ """
@@ -1,3 +1,4 @@
1
+ from collections.abc import Iterable, Iterator
1
2
  from typing import Any, Collection
2
3
  from simplibs.exception import ValidationError
3
4
  # Outers
@@ -37,14 +38,18 @@ class IsSupersetOf(Rule):
37
38
  def is_valid(self, value: Any) -> bool:
38
39
 
39
40
  # 1. Handling for when value is not iterable
40
- if not hasattr(value, "__iter__"):
41
+ if not isinstance(value, Iterable):
41
42
  return False
42
43
 
43
- # 2. Evaluate whether the input is a superset of the reference collection
44
+ # 2. A one-shot iterator would be consumed by this check — reject it untouched
45
+ if isinstance(value, Iterator):
46
+ return False
47
+
48
+ # 3. Evaluate whether the input is a superset of the reference collection
44
49
  try:
45
50
  return set(value) >= self.reference
46
51
 
47
- # 3. Fallback for unhashable items
52
+ # 4. Fallback for unhashable items
48
53
  except TypeError:
49
54
  return False
50
55
 
@@ -76,12 +81,21 @@ class IsSupersetOf(Rule):
76
81
 
77
82
  # 1. Prepare data
78
83
  # 1.1 When value is not iterable
79
- if not hasattr(value, "__iter__"):
84
+ if not isinstance(value, Iterable):
80
85
  problem = f"Value {value!r} of type '{type(value).__name__}' is not iterable."
81
86
  how_to_fix = "Provide an iterable container (e.g., list, tuple, set)."
82
87
  exception_type = TypeError
83
88
 
84
- # 1.2 When value is missing required elements (or contains unhashable elements)
89
+ # 1.2 When value is a one-shot iterator (validating it would have consumed it)
90
+ elif isinstance(value, Iterator):
91
+ problem = (
92
+ f"Value of type '{type(value).__name__}' is a one-shot iterator: "
93
+ "checking its items would consume it."
94
+ )
95
+ how_to_fix = "Pass a list, tuple or set (e.g. list(value)) instead of the iterator."
96
+ exception_type = TypeError
97
+
98
+ # 1.3 When value is missing required elements (or contains unhashable elements)
85
99
  else:
86
100
  try:
87
101
  missing = self.reference - set(value)
@@ -130,11 +144,13 @@ reference).
130
144
  ordering in Python's native `set.__repr__`, guaranteeing stable exception
131
145
  messages for assertions, unit testing, and logging aggregation.
132
146
  * **Explicit Interface Guard (`is_valid`):**
133
- Uses explicit `hasattr(value, "__iter__")` check to safely reject
134
- non-iterable objects. Catches `TypeError` only for unhashable elements.
147
+ Uses an explicit `isinstance(value, Iterable)` check to safely reject
148
+ non-iterable objects, and rejects one-shot iterators (see section 4).
149
+ Catches `TypeError` only for unhashable elements.
135
150
  * **Dual Diagnostic Path (`build_exception`):**
136
151
  Uses internal `if/else` branching to assemble:
137
152
  * A `TypeError` when the input is not iterable.
153
+ * A `TypeError` when the input is a one-shot iterator (the check would consume it).
138
154
  * A `ValueError` (`IS_SUPERSET_OF_ERROR`) when the input is missing
139
155
  required items, explicitly displaying missing elements
140
156
  (`self.reference - set(value)`).
@@ -158,4 +174,22 @@ reference).
158
174
  characters are abbreviated to "set(size=N)" in the description only, so a
159
175
  large reference never makes a composed text unreadable; the failure card keeps
160
176
  the full list in `expected`, where it is the useful detail.
161
- """
177
+
178
+ ---
179
+
180
+ ## 4. One-Shot Iterators Are Rejected, Not Consumed
181
+
182
+ This rule has to walk the whole value, and walking a generator (or any other
183
+ iterator) consumes it: the caller would get an exhausted iterator back, and
184
+ when the check fails, the diagnostics would re-read the already consumed value
185
+ and report nothing useful (an empty list of items). An iterator therefore
186
+ never reaches the check — `is_valid` returns `False` for it, and
187
+ `build_exception` explains why (`TypeError`, same `error_name` as the other
188
+ failures of this rule). Re-iterable containers (list, tuple, set, dict, range,
189
+ ...) are unaffected.
190
+
191
+ The iterable test is `isinstance(value, Iterable)` rather than
192
+ `hasattr(value, "__iter__")`: `hasattr` is also true for a class object such as
193
+ `list` itself, which `list(value)` then rejects with a `TypeError` raised out of
194
+ `is_valid`. Same reasoning as `IsReiterable` and `Iterable[T]`.
195
+ """
@@ -0,0 +1,133 @@
1
+ from collections.abc import Iterable, Iterator
2
+ from typing import Any
3
+ from simplibs.exception import ValidationError
4
+ # Outers
5
+ from ...base_class import Rule
6
+
7
+
8
+ class IsReiterable(Rule):
9
+ """Value must be iterable and safe to iterate more than once (not a one-shot iterator).
10
+
11
+ Rule:
12
+ isinstance(value, Iterable) and not isinstance(value, Iterator)
13
+
14
+ Example:
15
+ validate(value, IsReiterable())
16
+ """
17
+
18
+ __slots__ = ()
19
+
20
+ # ----------------------------------------------------------------------
21
+ # Rule definition
22
+ # ----------------------------------------------------------------------
23
+ def is_valid(self, value: Any) -> bool:
24
+
25
+ # 1. Iterable, but not an iterator (generators, file objects, map/zip/filter, ...)
26
+ return (
27
+ isinstance(value, Iterable)
28
+ and not isinstance(value, Iterator)
29
+ )
30
+
31
+ # ----------------------------------------------------------------------
32
+ # Description definition
33
+ # ----------------------------------------------------------------------
34
+ def describe(self) -> str:
35
+
36
+ # 1. Fixed phrase — the rule has no parameters
37
+ return "re-iterable"
38
+
39
+ # ----------------------------------------------------------------------
40
+ # Exception definition
41
+ # ----------------------------------------------------------------------
42
+ def build_exception(
43
+ self,
44
+ value: Any,
45
+ value_name: str | None = None,
46
+ context: str | None = None,
47
+ ) -> Exception:
48
+
49
+ # 1. Prepare data
50
+ # 1.1 When value is not iterable at all
51
+ if not isinstance(value, Iterable):
52
+ problem = f"Value {value!r} of type '{type(value).__name__}' is not iterable."
53
+ how_to_fix = "Provide a re-iterable container (e.g., list, tuple, set)."
54
+
55
+ # 1.2 When value is a one-shot iterator
56
+ else:
57
+ problem = (
58
+ f"Value of type '{type(value).__name__}' is a one-shot iterator: "
59
+ "checking its items would consume it, so the receiving code would get it exhausted."
60
+ )
61
+ how_to_fix = (
62
+ "Pass a list, tuple or set (e.g. list(value)) instead of the iterator, "
63
+ "or annotate the parameter as plain Iterable (without an item type)."
64
+ )
65
+
66
+ # 2. Build the exception
67
+ return ValidationError(
68
+ error_name="IS_REITERABLE_ERROR",
69
+ label=value_name,
70
+ expected="re-iterable value (e.g. list, tuple, set), not a one-shot iterator",
71
+ value=value,
72
+ problem=problem,
73
+ context=context,
74
+ how_to_fix=how_to_fix,
75
+ exception=TypeError,
76
+ )
77
+
78
+
79
+ _DESIGN_NOTES = """
80
+ # IsReiterable — Re-Iterable Value Validation Rule
81
+
82
+ ## Purpose
83
+ The `IsReiterable` rule validates that a value is iterable AND can be
84
+ iterated more than once — a list, tuple, set, dict, range, string, a dict
85
+ view — as opposed to a one-shot iterator (generator, file object,
86
+ `map`/`zip`/`filter`/`enumerate` result, a hand-written iterator class).
87
+
88
+ It exists for one reason: any rule that checks the *items* of a value
89
+ (`ForEach`, and through it `Iterable[T]`) has to walk it, and walking a
90
+ one-shot iterator consumes it. The value then reaches the validated code
91
+ exhausted, silently empty. `IsReiterable` is the cheap guard placed in
92
+ front of such a check.
93
+
94
+ ---
95
+
96
+ ## 1. Execution Rationale & Safeguards
97
+
98
+ * **ABC Checks, No Side Effects:**
99
+ `isinstance(value, Iterable)` and `isinstance(value, Iterator)` are
100
+ structural ABC checks (`__iter__` / `__iter__` + `__next__`). Unlike
101
+ calling `iter(value)`, they never create or advance anything.
102
+ * **Iterator Means One-Shot:**
103
+ By the iterator protocol an iterator returns itself from `__iter__`, so
104
+ a second pass sees what the first one left behind. A class whose
105
+ `__iter__` returns a *fresh* iterator each time is not an `Iterator`
106
+ and is accepted.
107
+ * **Why `Iterable`, Not `hasattr(value, "__iter__")`:**
108
+ `hasattr` is also true for a class object (`hasattr(list, "__iter__")`).
109
+ The ABC check looks at the type of the value, matching `IsInstance(Iterable)`
110
+ used by the typing layer. Objects iterable only through the legacy
111
+ `__getitem__` protocol are not recognized as iterable.
112
+ * **Dual Diagnostic Path (`build_exception`):**
113
+ Both failures are a `TypeError` (`IS_REITERABLE_ERROR`) with a different
114
+ `problem`: "not iterable", or "one-shot iterator" with the fix
115
+ (pass a list/tuple/set, or annotate plain `Iterable`).
116
+
117
+ ---
118
+
119
+ ## 2. What It Deliberately Does Not Do
120
+
121
+ * It never advances or inspects the value's items — that is the job of
122
+ `ForEach`.
123
+ * It does not try to "peek" at an iterator to be helpful; whatever is passed
124
+ in stays untouched.
125
+
126
+ ---
127
+
128
+ ## 3. Description
129
+
130
+ `describe()` returns "re-iterable" — what the value must be. A short
131
+ fragment that containers and the typing layer compose into larger texts;
132
+ the failure card keeps its own `expected` sentence.
133
+ """
@@ -5,6 +5,7 @@ from .IsDataclass import IsDataclass
5
5
  from .IsHashable import IsHashable
6
6
  from .IsInstance import IsInstance
7
7
  from .IsIterable import IsIterable
8
+ from .IsReiterable import IsReiterable
8
9
  from .IsSubclass import IsSubclass
9
10
  from .IsType import IsType
10
11
 
@@ -20,15 +21,16 @@ concrete contents.
20
21
 
21
22
  ## Internal Components Registry
22
23
 
23
- | Component | Type | Description |
24
- | :--------------------| :---- | :---------------------------------------------------------------------------|
25
- | `HasAttribute` | Class | Value must have a given attribute or method (duck typing). |
26
- | `HasLength` | Class | Value's `len()` must equal a target, or fall within min/max bounds. |
27
- | `IsCallable` | Class | Value must be callable. |
28
- | `IsDataclass` | Class | Value must be a dataclass instance or class. |
29
- | `IsHashable` | Class | Value must be hashable. |
30
- | `IsInstance` | Class | Value must be an instance of one or more given types. |
31
- | `IsIterable` | Class | Value must be iterable. |
32
- | `IsSubclass` | Class | Value must be a class that is a subclass of one or more given types. |
33
- | `IsType` | Class | Value must itself be a class/type object, not an instance. |
34
- """
24
+ | Component | Type | Description |
25
+ | :------------------- | :---- | :-------------------------------------------------------------------------- |
26
+ | `HasAttribute` | Class | Value must have a given attribute or method (duck typing). |
27
+ | `HasLength` | Class | Value's `len()` must equal a target, or fall within min/max bounds. |
28
+ | `IsCallable` | Class | Value must be callable. |
29
+ | `IsDataclass` | Class | Value must be a dataclass instance or class. |
30
+ | `IsHashable` | Class | Value must be hashable. |
31
+ | `IsInstance` | Class | Value must be an instance of one or more given types. |
32
+ | `IsIterable` | Class | Value must be iterable. |
33
+ | `IsReiterable` | Class | Value must be iterable and not a one-shot iterator (safe to walk twice). |
34
+ | `IsSubclass` | Class | Value must be a class that is a subclass of one or more given types. |
35
+ | `IsType` | Class | Value must itself be a class/type object, not an instance. |
36
+ """