enforce-rules 3.2.4__tar.gz → 3.2.6__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.
- {enforce_rules-3.2.4/src/enforce_rules.egg-info → enforce_rules-3.2.6}/PKG-INFO +30 -29
- {enforce_rules-3.2.4 → enforce_rules-3.2.6}/README.md +30 -29
- {enforce_rules-3.2.4 → enforce_rules-3.2.6}/pyproject.toml +1 -1
- {enforce_rules-3.2.4 → enforce_rules-3.2.6/src/enforce_rules.egg-info}/PKG-INFO +30 -29
- {enforce_rules-3.2.4 → enforce_rules-3.2.6}/LICENSE +0 -0
- {enforce_rules-3.2.4 → enforce_rules-3.2.6}/setup.cfg +0 -0
- {enforce_rules-3.2.4 → enforce_rules-3.2.6}/src/enforce_rules/__init__.py +0 -0
- {enforce_rules-3.2.4 → enforce_rules-3.2.6}/src/enforce_rules/enforce_rules.py +0 -0
- {enforce_rules-3.2.4 → enforce_rules-3.2.6}/src/enforce_rules.egg-info/SOURCES.txt +0 -0
- {enforce_rules-3.2.4 → enforce_rules-3.2.6}/src/enforce_rules.egg-info/dependency_links.txt +0 -0
- {enforce_rules-3.2.4 → enforce_rules-3.2.6}/src/enforce_rules.egg-info/top_level.txt +0 -0
- {enforce_rules-3.2.4 → enforce_rules-3.2.6}/tests/test_enforce_rules.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: enforce-rules
|
|
3
|
-
Version: 3.2.
|
|
3
|
+
Version: 3.2.6
|
|
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:
|
|
66
|
+
PATCH: 6
|
|
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
|
|
|
@@ -117,10 +117,11 @@ If the value passes, PER returns the original value unchanged.
|
|
|
117
117
|
|
|
118
118
|
This means validated values behave exactly like normal Python values.
|
|
119
119
|
|
|
120
|
-
Keywords and Usage
|
|
120
|
+
# Keywords and Usage
|
|
121
|
+
|
|
121
122
|
Below are all supported keywords.
|
|
122
123
|
|
|
123
|
-
length
|
|
124
|
+
## length
|
|
124
125
|
|
|
125
126
|
The length of the object must be exactly this.
|
|
126
127
|
|
|
@@ -128,70 +129,70 @@ The length of the object must be exactly this.
|
|
|
128
129
|
lst = validate([1, 2, 3, 4, 5], {"length": 5})
|
|
129
130
|
```
|
|
130
131
|
|
|
131
|
-
min_length
|
|
132
|
+
## min_length
|
|
132
133
|
|
|
133
134
|
Minimum length (inclusive).
|
|
134
135
|
|
|
135
136
|
```python
|
|
136
137
|
lst = validate(['a', 'b', 'c', 'd', 'e'], {"min_length": 3})
|
|
137
138
|
```
|
|
138
|
-
max_length
|
|
139
|
+
## max_length
|
|
139
140
|
|
|
140
141
|
Maximum length (inclusive).
|
|
141
142
|
|
|
142
143
|
```python
|
|
143
144
|
lst = validate([1, 2, 3, 4, 5, 6], {"max_length": 7})
|
|
144
145
|
```
|
|
145
|
-
min
|
|
146
|
+
## min
|
|
146
147
|
|
|
147
148
|
Minimum numeric value (inclusive).
|
|
148
149
|
|
|
149
150
|
```python
|
|
150
151
|
number = validate(10, {"min": 0})
|
|
151
152
|
```
|
|
152
|
-
max
|
|
153
|
+
## max
|
|
153
154
|
|
|
154
155
|
Maximum numeric value (inclusive).
|
|
155
156
|
|
|
156
157
|
```python
|
|
157
158
|
number = validate(10, {"max": 20})
|
|
158
159
|
```
|
|
159
|
-
allowed_values
|
|
160
|
+
## allowed_values
|
|
160
161
|
|
|
161
162
|
Similar to Literal; value must be one of the allowed values.
|
|
162
163
|
|
|
163
164
|
```python
|
|
164
165
|
val = validate("a", {"allowed_values": ("a", "b", "c", "d")})
|
|
165
166
|
```
|
|
166
|
-
invariant
|
|
167
|
+
## invariant
|
|
167
168
|
|
|
168
169
|
Value must be truthy.
|
|
169
170
|
|
|
170
171
|
```python
|
|
171
172
|
val = validate((0 == 0), {"invariant": True})
|
|
172
173
|
```
|
|
173
|
-
all_same
|
|
174
|
+
## all_same
|
|
174
175
|
|
|
175
176
|
All values in the collection must be the same.
|
|
176
177
|
|
|
177
178
|
```python
|
|
178
179
|
numbers = validate([1, 1, 1], {"all_same": True})
|
|
179
180
|
```
|
|
180
|
-
all_unique
|
|
181
|
+
## all_unique
|
|
181
182
|
|
|
182
183
|
All values in the collection must be unique.
|
|
183
184
|
|
|
184
185
|
```python
|
|
185
186
|
numbers = validate([1, 2, 3], {"all_unique": True})
|
|
186
187
|
```
|
|
187
|
-
non_empty
|
|
188
|
+
## non_empty
|
|
188
189
|
|
|
189
190
|
Collection must not be empty.
|
|
190
191
|
|
|
191
192
|
```python
|
|
192
193
|
my_strings = validate(['a', 'b', 'c'], {"non_empty": True})
|
|
193
194
|
```
|
|
194
|
-
no_nulls
|
|
195
|
+
## no_nulls
|
|
195
196
|
|
|
196
197
|
Collection must not contain None.
|
|
197
198
|
|
|
@@ -199,7 +200,7 @@ Collection must not contain None.
|
|
|
199
200
|
my_things = validate([1, 2, 3, "a", "b", "c"], {"no_nulls": True})
|
|
200
201
|
```
|
|
201
202
|
|
|
202
|
-
sorted
|
|
203
|
+
## sorted
|
|
203
204
|
|
|
204
205
|
List must be sorted (increasing or decreasing).
|
|
205
206
|
|
|
@@ -207,7 +208,7 @@ List must be sorted (increasing or decreasing).
|
|
|
207
208
|
numbers = validate([1, 5, 9], {"sorted": True})
|
|
208
209
|
```
|
|
209
210
|
|
|
210
|
-
increasing
|
|
211
|
+
## increasing
|
|
211
212
|
|
|
212
213
|
List must be strictly increasing.
|
|
213
214
|
|
|
@@ -221,42 +222,42 @@ List must be strictly decreasing.
|
|
|
221
222
|
```python
|
|
222
223
|
numbers = validate([9, 5, 1], {"decreasing": True})
|
|
223
224
|
```
|
|
224
|
-
sum_min
|
|
225
|
+
## sum_min
|
|
225
226
|
|
|
226
227
|
Minimum sum of the collection (inclusive).
|
|
227
228
|
|
|
228
229
|
```python
|
|
229
230
|
numbers = validate([10, 20, 30], {"sum_min": 50})
|
|
230
231
|
```
|
|
231
|
-
sum_max
|
|
232
|
+
## sum_max
|
|
232
233
|
|
|
233
234
|
Maximum sum of the collection (inclusive).
|
|
234
235
|
|
|
235
236
|
```python
|
|
236
237
|
numbers = validate([10, 20, 30], {"sum_max": 70})
|
|
237
238
|
```
|
|
238
|
-
element_min
|
|
239
|
+
## element_min
|
|
239
240
|
|
|
240
241
|
Minimum value for any element (inclusive).
|
|
241
242
|
|
|
242
243
|
```python
|
|
243
244
|
numbers = validate([10, 20, 30], {"element_min": 5})
|
|
244
245
|
```
|
|
245
|
-
element_max
|
|
246
|
+
## element_max
|
|
246
247
|
|
|
247
248
|
Maximum value for any element (inclusive).
|
|
248
249
|
|
|
249
250
|
```python
|
|
250
251
|
numbers = validate([10, 20, 30], {"element_max": 40})
|
|
251
252
|
```
|
|
252
|
-
regex
|
|
253
|
+
## regex
|
|
253
254
|
|
|
254
255
|
String must match the regex.
|
|
255
256
|
|
|
256
257
|
```python
|
|
257
258
|
cat_or_dog = validate("cat", {"regex": "cat|dog"})
|
|
258
259
|
```
|
|
259
|
-
regex_flags
|
|
260
|
+
## regex_flags
|
|
260
261
|
|
|
261
262
|
Turns out I didn't notice this in my code, until 1.1.0. This is the regex flags
|
|
262
263
|
|
|
@@ -264,7 +265,7 @@ Turns out I didn't notice this in my code, until 1.1.0. This is the regex flags
|
|
|
264
265
|
from re import RegexFlag
|
|
265
266
|
cat_or_dog = validate("cat", {"regex": "cat|dog", {"regex_flags": RegexFlag.I | RegexFlag.M | RegexFlag.X
|
|
266
267
|
```
|
|
267
|
-
before_date
|
|
268
|
+
## before_date
|
|
268
269
|
|
|
269
270
|
Value must be strictly before the given datetime.
|
|
270
271
|
|
|
@@ -272,14 +273,14 @@ Value must be strictly before the given datetime.
|
|
|
272
273
|
validate(datetime(1999, 8, 29), {"before_date": datetime(2000, 1, 1)})
|
|
273
274
|
```
|
|
274
275
|
|
|
275
|
-
after_date
|
|
276
|
+
## after_date
|
|
276
277
|
|
|
277
278
|
Value must be strictly after the given datetime.
|
|
278
279
|
```python
|
|
279
280
|
validate(datetime(2026, 8, 29), {"after_date": datetime(2000, 1, 1)})
|
|
280
281
|
```
|
|
281
282
|
|
|
282
|
-
piece_color
|
|
283
|
+
## piece_color
|
|
283
284
|
|
|
284
285
|
The piece must have this exact color.
|
|
285
286
|
|
|
@@ -287,7 +288,7 @@ The piece must have this exact color.
|
|
|
287
288
|
import chess
|
|
288
289
|
piece = validate(chess.Piece(chess.ROOK, chess.WHITE), {"piece_color": chess.WHITE})
|
|
289
290
|
```
|
|
290
|
-
piece_type
|
|
291
|
+
## piece_type
|
|
291
292
|
|
|
292
293
|
The piece must be exactly this type (e.g., chess.KNIGHT, chess.ROOK).
|
|
293
294
|
|
|
@@ -295,7 +296,7 @@ The piece must be exactly this type (e.g., chess.KNIGHT, chess.ROOK).
|
|
|
295
296
|
import chess
|
|
296
297
|
piece = validate(chess.Piece(chess.KNIGHT, chess.WHITE), {"piece_type": chess.KNIGHT})
|
|
297
298
|
```
|
|
298
|
-
chess_symbol
|
|
299
|
+
## chess_symbol
|
|
299
300
|
|
|
300
301
|
The piece’s symbol must match this string ("P", "n", "r", etc.).
|
|
301
302
|
|
|
@@ -304,7 +305,7 @@ import chess
|
|
|
304
305
|
piece = validate(chess.Piece(chess.ROOK, chess.BLACK), {"chess_symbol": "r"})
|
|
305
306
|
```
|
|
306
307
|
|
|
307
|
-
is_password
|
|
308
|
+
## is_password
|
|
308
309
|
|
|
309
310
|
The value must satisfy all password requirements when this is set to True.
|
|
310
311
|
|
|
@@ -320,7 +321,7 @@ Requirements (sorted):
|
|
|
320
321
|
password = validate("Abcdef!1", {"is_password": True})
|
|
321
322
|
```
|
|
322
323
|
|
|
323
|
-
must_be_true
|
|
324
|
+
## must_be_true
|
|
324
325
|
|
|
325
326
|
Custom rule: a function that returns True for allowed values.
|
|
326
327
|
|
|
@@ -7,7 +7,7 @@ MAJOR: 3
|
|
|
7
7
|
|
|
8
8
|
MINOR: 2
|
|
9
9
|
|
|
10
|
-
PATCH:
|
|
10
|
+
PATCH: 6
|
|
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
|
|
|
@@ -61,10 +61,11 @@ If the value passes, PER returns the original value unchanged.
|
|
|
61
61
|
|
|
62
62
|
This means validated values behave exactly like normal Python values.
|
|
63
63
|
|
|
64
|
-
Keywords and Usage
|
|
64
|
+
# Keywords and Usage
|
|
65
|
+
|
|
65
66
|
Below are all supported keywords.
|
|
66
67
|
|
|
67
|
-
length
|
|
68
|
+
## length
|
|
68
69
|
|
|
69
70
|
The length of the object must be exactly this.
|
|
70
71
|
|
|
@@ -72,70 +73,70 @@ The length of the object must be exactly this.
|
|
|
72
73
|
lst = validate([1, 2, 3, 4, 5], {"length": 5})
|
|
73
74
|
```
|
|
74
75
|
|
|
75
|
-
min_length
|
|
76
|
+
## min_length
|
|
76
77
|
|
|
77
78
|
Minimum length (inclusive).
|
|
78
79
|
|
|
79
80
|
```python
|
|
80
81
|
lst = validate(['a', 'b', 'c', 'd', 'e'], {"min_length": 3})
|
|
81
82
|
```
|
|
82
|
-
max_length
|
|
83
|
+
## max_length
|
|
83
84
|
|
|
84
85
|
Maximum length (inclusive).
|
|
85
86
|
|
|
86
87
|
```python
|
|
87
88
|
lst = validate([1, 2, 3, 4, 5, 6], {"max_length": 7})
|
|
88
89
|
```
|
|
89
|
-
min
|
|
90
|
+
## min
|
|
90
91
|
|
|
91
92
|
Minimum numeric value (inclusive).
|
|
92
93
|
|
|
93
94
|
```python
|
|
94
95
|
number = validate(10, {"min": 0})
|
|
95
96
|
```
|
|
96
|
-
max
|
|
97
|
+
## max
|
|
97
98
|
|
|
98
99
|
Maximum numeric value (inclusive).
|
|
99
100
|
|
|
100
101
|
```python
|
|
101
102
|
number = validate(10, {"max": 20})
|
|
102
103
|
```
|
|
103
|
-
allowed_values
|
|
104
|
+
## allowed_values
|
|
104
105
|
|
|
105
106
|
Similar to Literal; value must be one of the allowed values.
|
|
106
107
|
|
|
107
108
|
```python
|
|
108
109
|
val = validate("a", {"allowed_values": ("a", "b", "c", "d")})
|
|
109
110
|
```
|
|
110
|
-
invariant
|
|
111
|
+
## invariant
|
|
111
112
|
|
|
112
113
|
Value must be truthy.
|
|
113
114
|
|
|
114
115
|
```python
|
|
115
116
|
val = validate((0 == 0), {"invariant": True})
|
|
116
117
|
```
|
|
117
|
-
all_same
|
|
118
|
+
## all_same
|
|
118
119
|
|
|
119
120
|
All values in the collection must be the same.
|
|
120
121
|
|
|
121
122
|
```python
|
|
122
123
|
numbers = validate([1, 1, 1], {"all_same": True})
|
|
123
124
|
```
|
|
124
|
-
all_unique
|
|
125
|
+
## all_unique
|
|
125
126
|
|
|
126
127
|
All values in the collection must be unique.
|
|
127
128
|
|
|
128
129
|
```python
|
|
129
130
|
numbers = validate([1, 2, 3], {"all_unique": True})
|
|
130
131
|
```
|
|
131
|
-
non_empty
|
|
132
|
+
## non_empty
|
|
132
133
|
|
|
133
134
|
Collection must not be empty.
|
|
134
135
|
|
|
135
136
|
```python
|
|
136
137
|
my_strings = validate(['a', 'b', 'c'], {"non_empty": True})
|
|
137
138
|
```
|
|
138
|
-
no_nulls
|
|
139
|
+
## no_nulls
|
|
139
140
|
|
|
140
141
|
Collection must not contain None.
|
|
141
142
|
|
|
@@ -143,7 +144,7 @@ Collection must not contain None.
|
|
|
143
144
|
my_things = validate([1, 2, 3, "a", "b", "c"], {"no_nulls": True})
|
|
144
145
|
```
|
|
145
146
|
|
|
146
|
-
sorted
|
|
147
|
+
## sorted
|
|
147
148
|
|
|
148
149
|
List must be sorted (increasing or decreasing).
|
|
149
150
|
|
|
@@ -151,7 +152,7 @@ List must be sorted (increasing or decreasing).
|
|
|
151
152
|
numbers = validate([1, 5, 9], {"sorted": True})
|
|
152
153
|
```
|
|
153
154
|
|
|
154
|
-
increasing
|
|
155
|
+
## increasing
|
|
155
156
|
|
|
156
157
|
List must be strictly increasing.
|
|
157
158
|
|
|
@@ -165,42 +166,42 @@ List must be strictly decreasing.
|
|
|
165
166
|
```python
|
|
166
167
|
numbers = validate([9, 5, 1], {"decreasing": True})
|
|
167
168
|
```
|
|
168
|
-
sum_min
|
|
169
|
+
## sum_min
|
|
169
170
|
|
|
170
171
|
Minimum sum of the collection (inclusive).
|
|
171
172
|
|
|
172
173
|
```python
|
|
173
174
|
numbers = validate([10, 20, 30], {"sum_min": 50})
|
|
174
175
|
```
|
|
175
|
-
sum_max
|
|
176
|
+
## sum_max
|
|
176
177
|
|
|
177
178
|
Maximum sum of the collection (inclusive).
|
|
178
179
|
|
|
179
180
|
```python
|
|
180
181
|
numbers = validate([10, 20, 30], {"sum_max": 70})
|
|
181
182
|
```
|
|
182
|
-
element_min
|
|
183
|
+
## element_min
|
|
183
184
|
|
|
184
185
|
Minimum value for any element (inclusive).
|
|
185
186
|
|
|
186
187
|
```python
|
|
187
188
|
numbers = validate([10, 20, 30], {"element_min": 5})
|
|
188
189
|
```
|
|
189
|
-
element_max
|
|
190
|
+
## element_max
|
|
190
191
|
|
|
191
192
|
Maximum value for any element (inclusive).
|
|
192
193
|
|
|
193
194
|
```python
|
|
194
195
|
numbers = validate([10, 20, 30], {"element_max": 40})
|
|
195
196
|
```
|
|
196
|
-
regex
|
|
197
|
+
## regex
|
|
197
198
|
|
|
198
199
|
String must match the regex.
|
|
199
200
|
|
|
200
201
|
```python
|
|
201
202
|
cat_or_dog = validate("cat", {"regex": "cat|dog"})
|
|
202
203
|
```
|
|
203
|
-
regex_flags
|
|
204
|
+
## regex_flags
|
|
204
205
|
|
|
205
206
|
Turns out I didn't notice this in my code, until 1.1.0. This is the regex flags
|
|
206
207
|
|
|
@@ -208,7 +209,7 @@ Turns out I didn't notice this in my code, until 1.1.0. This is the regex flags
|
|
|
208
209
|
from re import RegexFlag
|
|
209
210
|
cat_or_dog = validate("cat", {"regex": "cat|dog", {"regex_flags": RegexFlag.I | RegexFlag.M | RegexFlag.X
|
|
210
211
|
```
|
|
211
|
-
before_date
|
|
212
|
+
## before_date
|
|
212
213
|
|
|
213
214
|
Value must be strictly before the given datetime.
|
|
214
215
|
|
|
@@ -216,14 +217,14 @@ Value must be strictly before the given datetime.
|
|
|
216
217
|
validate(datetime(1999, 8, 29), {"before_date": datetime(2000, 1, 1)})
|
|
217
218
|
```
|
|
218
219
|
|
|
219
|
-
after_date
|
|
220
|
+
## after_date
|
|
220
221
|
|
|
221
222
|
Value must be strictly after the given datetime.
|
|
222
223
|
```python
|
|
223
224
|
validate(datetime(2026, 8, 29), {"after_date": datetime(2000, 1, 1)})
|
|
224
225
|
```
|
|
225
226
|
|
|
226
|
-
piece_color
|
|
227
|
+
## piece_color
|
|
227
228
|
|
|
228
229
|
The piece must have this exact color.
|
|
229
230
|
|
|
@@ -231,7 +232,7 @@ The piece must have this exact color.
|
|
|
231
232
|
import chess
|
|
232
233
|
piece = validate(chess.Piece(chess.ROOK, chess.WHITE), {"piece_color": chess.WHITE})
|
|
233
234
|
```
|
|
234
|
-
piece_type
|
|
235
|
+
## piece_type
|
|
235
236
|
|
|
236
237
|
The piece must be exactly this type (e.g., chess.KNIGHT, chess.ROOK).
|
|
237
238
|
|
|
@@ -239,7 +240,7 @@ The piece must be exactly this type (e.g., chess.KNIGHT, chess.ROOK).
|
|
|
239
240
|
import chess
|
|
240
241
|
piece = validate(chess.Piece(chess.KNIGHT, chess.WHITE), {"piece_type": chess.KNIGHT})
|
|
241
242
|
```
|
|
242
|
-
chess_symbol
|
|
243
|
+
## chess_symbol
|
|
243
244
|
|
|
244
245
|
The piece’s symbol must match this string ("P", "n", "r", etc.).
|
|
245
246
|
|
|
@@ -248,7 +249,7 @@ import chess
|
|
|
248
249
|
piece = validate(chess.Piece(chess.ROOK, chess.BLACK), {"chess_symbol": "r"})
|
|
249
250
|
```
|
|
250
251
|
|
|
251
|
-
is_password
|
|
252
|
+
## is_password
|
|
252
253
|
|
|
253
254
|
The value must satisfy all password requirements when this is set to True.
|
|
254
255
|
|
|
@@ -264,7 +265,7 @@ Requirements (sorted):
|
|
|
264
265
|
password = validate("Abcdef!1", {"is_password": True})
|
|
265
266
|
```
|
|
266
267
|
|
|
267
|
-
must_be_true
|
|
268
|
+
## must_be_true
|
|
268
269
|
|
|
269
270
|
Custom rule: a function that returns True for allowed values.
|
|
270
271
|
|
|
@@ -336,4 +337,4 @@ Minor bumps always reset PATCH to 0
|
|
|
336
337
|
|
|
337
338
|
Credits:
|
|
338
339
|
* Copilot
|
|
339
|
-
* Dad
|
|
340
|
+
* Dad
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: enforce-rules
|
|
3
|
-
Version: 3.2.
|
|
3
|
+
Version: 3.2.6
|
|
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:
|
|
66
|
+
PATCH: 6
|
|
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
|
|
|
@@ -117,10 +117,11 @@ If the value passes, PER returns the original value unchanged.
|
|
|
117
117
|
|
|
118
118
|
This means validated values behave exactly like normal Python values.
|
|
119
119
|
|
|
120
|
-
Keywords and Usage
|
|
120
|
+
# Keywords and Usage
|
|
121
|
+
|
|
121
122
|
Below are all supported keywords.
|
|
122
123
|
|
|
123
|
-
length
|
|
124
|
+
## length
|
|
124
125
|
|
|
125
126
|
The length of the object must be exactly this.
|
|
126
127
|
|
|
@@ -128,70 +129,70 @@ The length of the object must be exactly this.
|
|
|
128
129
|
lst = validate([1, 2, 3, 4, 5], {"length": 5})
|
|
129
130
|
```
|
|
130
131
|
|
|
131
|
-
min_length
|
|
132
|
+
## min_length
|
|
132
133
|
|
|
133
134
|
Minimum length (inclusive).
|
|
134
135
|
|
|
135
136
|
```python
|
|
136
137
|
lst = validate(['a', 'b', 'c', 'd', 'e'], {"min_length": 3})
|
|
137
138
|
```
|
|
138
|
-
max_length
|
|
139
|
+
## max_length
|
|
139
140
|
|
|
140
141
|
Maximum length (inclusive).
|
|
141
142
|
|
|
142
143
|
```python
|
|
143
144
|
lst = validate([1, 2, 3, 4, 5, 6], {"max_length": 7})
|
|
144
145
|
```
|
|
145
|
-
min
|
|
146
|
+
## min
|
|
146
147
|
|
|
147
148
|
Minimum numeric value (inclusive).
|
|
148
149
|
|
|
149
150
|
```python
|
|
150
151
|
number = validate(10, {"min": 0})
|
|
151
152
|
```
|
|
152
|
-
max
|
|
153
|
+
## max
|
|
153
154
|
|
|
154
155
|
Maximum numeric value (inclusive).
|
|
155
156
|
|
|
156
157
|
```python
|
|
157
158
|
number = validate(10, {"max": 20})
|
|
158
159
|
```
|
|
159
|
-
allowed_values
|
|
160
|
+
## allowed_values
|
|
160
161
|
|
|
161
162
|
Similar to Literal; value must be one of the allowed values.
|
|
162
163
|
|
|
163
164
|
```python
|
|
164
165
|
val = validate("a", {"allowed_values": ("a", "b", "c", "d")})
|
|
165
166
|
```
|
|
166
|
-
invariant
|
|
167
|
+
## invariant
|
|
167
168
|
|
|
168
169
|
Value must be truthy.
|
|
169
170
|
|
|
170
171
|
```python
|
|
171
172
|
val = validate((0 == 0), {"invariant": True})
|
|
172
173
|
```
|
|
173
|
-
all_same
|
|
174
|
+
## all_same
|
|
174
175
|
|
|
175
176
|
All values in the collection must be the same.
|
|
176
177
|
|
|
177
178
|
```python
|
|
178
179
|
numbers = validate([1, 1, 1], {"all_same": True})
|
|
179
180
|
```
|
|
180
|
-
all_unique
|
|
181
|
+
## all_unique
|
|
181
182
|
|
|
182
183
|
All values in the collection must be unique.
|
|
183
184
|
|
|
184
185
|
```python
|
|
185
186
|
numbers = validate([1, 2, 3], {"all_unique": True})
|
|
186
187
|
```
|
|
187
|
-
non_empty
|
|
188
|
+
## non_empty
|
|
188
189
|
|
|
189
190
|
Collection must not be empty.
|
|
190
191
|
|
|
191
192
|
```python
|
|
192
193
|
my_strings = validate(['a', 'b', 'c'], {"non_empty": True})
|
|
193
194
|
```
|
|
194
|
-
no_nulls
|
|
195
|
+
## no_nulls
|
|
195
196
|
|
|
196
197
|
Collection must not contain None.
|
|
197
198
|
|
|
@@ -199,7 +200,7 @@ Collection must not contain None.
|
|
|
199
200
|
my_things = validate([1, 2, 3, "a", "b", "c"], {"no_nulls": True})
|
|
200
201
|
```
|
|
201
202
|
|
|
202
|
-
sorted
|
|
203
|
+
## sorted
|
|
203
204
|
|
|
204
205
|
List must be sorted (increasing or decreasing).
|
|
205
206
|
|
|
@@ -207,7 +208,7 @@ List must be sorted (increasing or decreasing).
|
|
|
207
208
|
numbers = validate([1, 5, 9], {"sorted": True})
|
|
208
209
|
```
|
|
209
210
|
|
|
210
|
-
increasing
|
|
211
|
+
## increasing
|
|
211
212
|
|
|
212
213
|
List must be strictly increasing.
|
|
213
214
|
|
|
@@ -221,42 +222,42 @@ List must be strictly decreasing.
|
|
|
221
222
|
```python
|
|
222
223
|
numbers = validate([9, 5, 1], {"decreasing": True})
|
|
223
224
|
```
|
|
224
|
-
sum_min
|
|
225
|
+
## sum_min
|
|
225
226
|
|
|
226
227
|
Minimum sum of the collection (inclusive).
|
|
227
228
|
|
|
228
229
|
```python
|
|
229
230
|
numbers = validate([10, 20, 30], {"sum_min": 50})
|
|
230
231
|
```
|
|
231
|
-
sum_max
|
|
232
|
+
## sum_max
|
|
232
233
|
|
|
233
234
|
Maximum sum of the collection (inclusive).
|
|
234
235
|
|
|
235
236
|
```python
|
|
236
237
|
numbers = validate([10, 20, 30], {"sum_max": 70})
|
|
237
238
|
```
|
|
238
|
-
element_min
|
|
239
|
+
## element_min
|
|
239
240
|
|
|
240
241
|
Minimum value for any element (inclusive).
|
|
241
242
|
|
|
242
243
|
```python
|
|
243
244
|
numbers = validate([10, 20, 30], {"element_min": 5})
|
|
244
245
|
```
|
|
245
|
-
element_max
|
|
246
|
+
## element_max
|
|
246
247
|
|
|
247
248
|
Maximum value for any element (inclusive).
|
|
248
249
|
|
|
249
250
|
```python
|
|
250
251
|
numbers = validate([10, 20, 30], {"element_max": 40})
|
|
251
252
|
```
|
|
252
|
-
regex
|
|
253
|
+
## regex
|
|
253
254
|
|
|
254
255
|
String must match the regex.
|
|
255
256
|
|
|
256
257
|
```python
|
|
257
258
|
cat_or_dog = validate("cat", {"regex": "cat|dog"})
|
|
258
259
|
```
|
|
259
|
-
regex_flags
|
|
260
|
+
## regex_flags
|
|
260
261
|
|
|
261
262
|
Turns out I didn't notice this in my code, until 1.1.0. This is the regex flags
|
|
262
263
|
|
|
@@ -264,7 +265,7 @@ Turns out I didn't notice this in my code, until 1.1.0. This is the regex flags
|
|
|
264
265
|
from re import RegexFlag
|
|
265
266
|
cat_or_dog = validate("cat", {"regex": "cat|dog", {"regex_flags": RegexFlag.I | RegexFlag.M | RegexFlag.X
|
|
266
267
|
```
|
|
267
|
-
before_date
|
|
268
|
+
## before_date
|
|
268
269
|
|
|
269
270
|
Value must be strictly before the given datetime.
|
|
270
271
|
|
|
@@ -272,14 +273,14 @@ Value must be strictly before the given datetime.
|
|
|
272
273
|
validate(datetime(1999, 8, 29), {"before_date": datetime(2000, 1, 1)})
|
|
273
274
|
```
|
|
274
275
|
|
|
275
|
-
after_date
|
|
276
|
+
## after_date
|
|
276
277
|
|
|
277
278
|
Value must be strictly after the given datetime.
|
|
278
279
|
```python
|
|
279
280
|
validate(datetime(2026, 8, 29), {"after_date": datetime(2000, 1, 1)})
|
|
280
281
|
```
|
|
281
282
|
|
|
282
|
-
piece_color
|
|
283
|
+
## piece_color
|
|
283
284
|
|
|
284
285
|
The piece must have this exact color.
|
|
285
286
|
|
|
@@ -287,7 +288,7 @@ The piece must have this exact color.
|
|
|
287
288
|
import chess
|
|
288
289
|
piece = validate(chess.Piece(chess.ROOK, chess.WHITE), {"piece_color": chess.WHITE})
|
|
289
290
|
```
|
|
290
|
-
piece_type
|
|
291
|
+
## piece_type
|
|
291
292
|
|
|
292
293
|
The piece must be exactly this type (e.g., chess.KNIGHT, chess.ROOK).
|
|
293
294
|
|
|
@@ -295,7 +296,7 @@ The piece must be exactly this type (e.g., chess.KNIGHT, chess.ROOK).
|
|
|
295
296
|
import chess
|
|
296
297
|
piece = validate(chess.Piece(chess.KNIGHT, chess.WHITE), {"piece_type": chess.KNIGHT})
|
|
297
298
|
```
|
|
298
|
-
chess_symbol
|
|
299
|
+
## chess_symbol
|
|
299
300
|
|
|
300
301
|
The piece’s symbol must match this string ("P", "n", "r", etc.).
|
|
301
302
|
|
|
@@ -304,7 +305,7 @@ import chess
|
|
|
304
305
|
piece = validate(chess.Piece(chess.ROOK, chess.BLACK), {"chess_symbol": "r"})
|
|
305
306
|
```
|
|
306
307
|
|
|
307
|
-
is_password
|
|
308
|
+
## is_password
|
|
308
309
|
|
|
309
310
|
The value must satisfy all password requirements when this is set to True.
|
|
310
311
|
|
|
@@ -320,7 +321,7 @@ Requirements (sorted):
|
|
|
320
321
|
password = validate("Abcdef!1", {"is_password": True})
|
|
321
322
|
```
|
|
322
323
|
|
|
323
|
-
must_be_true
|
|
324
|
+
## must_be_true
|
|
324
325
|
|
|
325
326
|
Custom rule: a function that returns True for allowed values.
|
|
326
327
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|