enforce-rules 3.2.0__tar.gz → 3.2.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: enforce-rules
3
- Version: 3.2.0
3
+ Version: 3.2.2
4
4
  Summary: Runtime rule validation for Python using dictionary-based constraints.
5
5
  Author: Jake Loepker, Microsoft Copilot (AI Assistant)
6
6
  License: BSD 3-Clause License
@@ -63,7 +63,7 @@ MAJOR: 3
63
63
 
64
64
  MINOR: 2
65
65
 
66
- PATCH: 0
66
+ PATCH: 2
67
67
 
68
68
  If you need to catch up, you can see the full version history in the [CHANGELOG](https://github.com/Loepker-James/enforce-rules/blob/main/CHANGELOG.md).
69
69
 
@@ -7,7 +7,7 @@ MAJOR: 3
7
7
 
8
8
  MINOR: 2
9
9
 
10
- PATCH: 0
10
+ PATCH: 2
11
11
 
12
12
  If you need to catch up, you can see the full version history in the [CHANGELOG](https://github.com/Loepker-James/enforce-rules/blob/main/CHANGELOG.md).
13
13
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "enforce-rules"
3
- version = "3.2.0"
3
+ version = "3.2.2"
4
4
  description = "Runtime rule validation for Python using dictionary-based constraints."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -1,4 +1,4 @@
1
- from typing import Dict, Callable, Literal, TypeVar
1
+ from typing import Dict, Callable, Literal, TypeVar, TypedDict, TypeAlias
2
2
  from collections.abc import Iterable, Sequence, Container
3
3
  import re
4
4
  from datetime import datetime
@@ -170,7 +170,37 @@ def _validate_is_password(value: str, rule: bool) -> None:
170
170
  # VALIDATE() — DEFINED LAST
171
171
  # -----------------------------
172
172
  T = TypeVar("T")
173
- def validate(value: T, rules: Dict[str, object]) -> T:
173
+ Number: TypeAlias = int | float
174
+
175
+ class ValidateDict(TypedDict, total=False):
176
+ length: int
177
+ min_length: int
178
+ max_length: int
179
+ min: Number
180
+ max: Number
181
+ allowed_values: Iterable
182
+ invariant: bool
183
+ all_same: bool
184
+ all_unique: bool
185
+ non_empty: bool
186
+ no_nulls: bool
187
+ sorted: bool
188
+ increasing: bool
189
+ decreasing: bool
190
+ sum_min: Number
191
+ sum_max: Number
192
+ element_min: Number
193
+ element_max: Number
194
+ regex: str
195
+ regex_flags: object
196
+ must_be_true: Callable[[object], bool]
197
+ before_date: datetime
198
+ after_date: datetime
199
+ piece_color: bool
200
+ piece_type: Literal[1, 2, 3, 4, 5, 6]
201
+ chess_symbol: Literal["p", "n", "b", "r", "q", "k", "P", "N", "B", "R", "Q", "K"]
202
+
203
+ def validate(value: T, rules: ValidateDict) -> T:
174
204
  # Do not mutate value
175
205
  """
176
206
  Validate a value against a dictionary of rules.
@@ -237,10 +267,10 @@ def validate(value: T, rules: Dict[str, object]) -> T:
237
267
  raise ValueError(f"Unknown rule: {key}")
238
268
 
239
269
  return value
240
-
241
- def is_valid(value: object, rules: Dict[str, object]) -> bool:
270
+
271
+ def is_valid(value: object, rules: ValidateDict) -> bool:
242
272
  try:
243
273
  validate(value, rules)
244
274
  return True
245
275
  except:
246
- return False
276
+ return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: enforce-rules
3
- Version: 3.2.0
3
+ Version: 3.2.2
4
4
  Summary: Runtime rule validation for Python using dictionary-based constraints.
5
5
  Author: Jake Loepker, Microsoft Copilot (AI Assistant)
6
6
  License: BSD 3-Clause License
@@ -63,7 +63,7 @@ MAJOR: 3
63
63
 
64
64
  MINOR: 2
65
65
 
66
- PATCH: 0
66
+ PATCH: 2
67
67
 
68
68
  If you need to catch up, you can see the full version history in the [CHANGELOG](https://github.com/Loepker-James/enforce-rules/blob/main/CHANGELOG.md).
69
69
 
File without changes
File without changes