Skip to content

Commit c0d1631

Browse files
authored
Let's be gentlemen (and use Input instead of Value) (#201)
* let us be gentlemen: s/must/should/g * replace Value with Input in error messages * sed was a bit too optimistic
1 parent 1749039 commit c0d1631

40 files changed

+431
-402
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ except ValidationError as e:
5959
"""
6060
1 validation error for model
6161
age
62-
Value must be greater than or equal to 18
62+
Input should be greater than or equal to 18
6363
[kind=greater_than_equal, context={ge: 18}, input_value=11, input_type=int]
6464
"""
6565
```

src/errors/kinds.rs

Lines changed: 69 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -26,186 +26,195 @@ pub enum ErrorKind {
2626
RecursionLoop,
2727
// ---------------------
2828
// typed dict specific errors
29-
#[strum(message = "Value must be a valid dictionary or instance to extract fields from")]
29+
#[strum(message = "Input should be a valid dictionary or instance to extract fields from")]
3030
DictAttributesType,
3131
#[strum(message = "Field required")]
3232
Missing,
33-
#[strum(message = "Extra values are not permitted")]
33+
#[strum(message = "Extra inputs are not permitted")]
3434
ExtraForbidden,
35-
#[strum(message = "Keys must be strings")]
35+
#[strum(message = "Keys should be strings")]
3636
InvalidKey,
3737
#[strum(message = "Error extracting attribute: {error}")]
3838
GetAttributeError {
3939
error: String,
4040
},
4141
// ---------------------
4242
// model class specific errors
43-
#[strum(message = "Value must be an instance of {class_name}")]
43+
#[strum(message = "Input should be an instance of {class_name}")]
4444
ModelClassType {
4545
class_name: String,
4646
},
4747
// ---------------------
4848
// None errors
49-
#[strum(message = "Value must be None/null")]
49+
#[strum(message = "Input should be None/null")]
5050
NoneRequired,
5151
// boolean errors
52-
#[strum(message = "Value must be a valid boolean")]
52+
#[strum(message = "Input should be a valid boolean")]
5353
Bool,
5454
// ---------------------
5555
// generic comparison errors - used for all inequality comparisons except int and float which have their
5656
// own type, bounds arguments are Strings so they can be created from any type
57-
#[strum(message = "Value must be greater than {gt}")]
57+
#[strum(message = "Input should be greater than {gt}")]
5858
GreaterThan {
5959
gt: String,
6060
},
61-
#[strum(message = "Value must be greater than or equal to {ge}")]
61+
#[strum(message = "Input should be greater than or equal to {ge}")]
6262
GreaterThanEqual {
6363
ge: String,
6464
},
65-
#[strum(message = "Value must be less than {lt}")]
65+
#[strum(message = "Input should be less than {lt}")]
6666
LessThan {
6767
lt: String,
6868
},
69-
#[strum(message = "Value must be less than or equal to {le}")]
69+
#[strum(message = "Input should be less than or equal to {le}")]
7070
LessThanEqual {
7171
le: String,
7272
},
7373
// ---------------------
7474
// generic length errors - used for everything with a length except strings and bytes which need custom messages
7575
#[strum(
76-
message = "Input must have at least {min_length} item{expected_plural}, got {input_length} item{input_plural}"
76+
message = "Input should have at least {min_length} item{expected_plural}, got {input_length} item{input_plural}"
7777
)]
7878
TooShort {
7979
min_length: usize,
8080
input_length: usize,
8181
},
8282
#[strum(
83-
message = "Input must have at most {max_length} item{expected_plural}, got {input_length} item{input_plural}"
83+
message = "Input should have at most {max_length} item{expected_plural}, got {input_length} item{input_plural}"
8484
)]
8585
TooLong {
8686
max_length: usize,
8787
input_length: usize,
8888
},
8989
// ---------------------
9090
// string errors
91-
#[strum(message = "Value must be a valid string")]
91+
#[strum(message = "Input should be a valid string")]
9292
StrType,
93-
#[strum(message = "Value must be a valid string, unable to parse raw data as a unicode string")]
93+
#[strum(message = "Input should be a valid string, unable to parse raw data as a unicode string")]
9494
StrUnicode,
9595
#[strum(
96-
message = "String must have at least {min_length} characters",
96+
message = "String should have at least {min_length} characters",
9797
serialize = "too_short"
9898
)]
9999
StrTooShort {
100100
min_length: usize,
101101
},
102-
#[strum(message = "String must have at most {max_length} characters", serialize = "too_long")]
102+
#[strum(
103+
message = "String should have at most {max_length} characters",
104+
serialize = "too_long"
105+
)]
103106
StrTooLong {
104107
max_length: usize,
105108
},
106-
#[strum(message = "String must match pattern '{pattern}'")]
109+
#[strum(message = "String should match pattern '{pattern}'")]
107110
StrPatternMismatch {
108111
pattern: String,
109112
},
110113
// ---------------------
111114
// dict errors
112-
#[strum(message = "Value must be a valid dictionary")]
115+
#[strum(message = "Input should be a valid dictionary")]
113116
DictType,
114117
#[strum(message = "Unable to convert mapping to a dictionary, error: {error}")]
115118
DictFromMapping {
116119
error: String,
117120
},
118121
// ---------------------
119122
// list errors
120-
#[strum(message = "Value must be a valid list/array")]
123+
#[strum(message = "Input should be a valid list/array")]
121124
ListType,
122125
// ---------------------
123126
// tuple errors
124-
#[strum(message = "Value must be a valid tuple")]
127+
#[strum(message = "Input should be a valid tuple")]
125128
TupleType,
126129
// ---------------------
127130
// set errors
128-
#[strum(message = "Value must be a valid set")]
131+
#[strum(message = "Input should be a valid set")]
129132
SetType,
130133
// ---------------------
131134
// bool errors
132-
#[strum(message = "Value must be a valid boolean")]
135+
#[strum(message = "Input should be a valid boolean")]
133136
BoolType,
134-
#[strum(message = "Value must be a valid boolean, unable to interpret input")]
137+
#[strum(message = "Input should be a valid boolean, unable to interpret input")]
135138
BoolParsing,
136139
// ---------------------
137140
// int errors
138-
#[strum(message = "Value must be a valid integer")]
141+
#[strum(message = "Input should be a valid integer")]
139142
IntType,
140-
#[strum(message = "Value must be a valid integer, unable to parse string as an integer")]
143+
#[strum(message = "Input should be a valid integer, unable to parse string as an integer")]
141144
IntParsing,
142-
#[strum(message = "Value must be a valid integer, got a number with a fractional part")]
145+
#[strum(message = "Input should be a valid integer, got a number with a fractional part")]
143146
IntFromFloat,
144-
#[strum(message = "Value must be a valid integer, got {nan_value}")]
147+
#[strum(message = "Input should be a valid integer, got {nan_value}")]
145148
IntNan {
146149
nan_value: &'static str,
147150
},
148-
#[strum(serialize = "multiple_of", message = "Value must be a multiple of {multiple_of}")]
151+
#[strum(serialize = "multiple_of", message = "Input should be a multiple of {multiple_of}")]
149152
IntMultipleOf {
150153
multiple_of: i64,
151154
},
152-
#[strum(serialize = "greater_than", message = "Value must be greater than {gt}")]
155+
#[strum(serialize = "greater_than", message = "Input should be greater than {gt}")]
153156
IntGreaterThan {
154157
gt: i64,
155158
},
156159
#[strum(
157160
serialize = "greater_than_equal",
158-
message = "Value must be greater than or equal to {ge}"
161+
message = "Input should be greater than or equal to {ge}"
159162
)]
160163
IntGreaterThanEqual {
161164
ge: i64,
162165
},
163-
#[strum(serialize = "less_than", message = "Value must be less than {lt}")]
166+
#[strum(serialize = "less_than", message = "Input should be less than {lt}")]
164167
IntLessThan {
165168
lt: i64,
166169
},
167-
#[strum(serialize = "less_than_equal", message = "Value must be less than or equal to {le}")]
170+
#[strum(
171+
serialize = "less_than_equal",
172+
message = "Input should be less than or equal to {le}"
173+
)]
168174
IntLessThanEqual {
169175
le: i64,
170176
},
171177
// ---------------------
172178
// float errors
173-
#[strum(message = "Value must be a valid number")]
179+
#[strum(message = "Input should be a valid number")]
174180
FloatType,
175-
#[strum(message = "Value must be a valid number, unable to parse string as an number")]
181+
#[strum(message = "Input should be a valid number, unable to parse string as an number")]
176182
FloatParsing,
177-
#[strum(serialize = "multiple_of", message = "Value must be a multiple of {multiple_of}")]
183+
#[strum(serialize = "multiple_of", message = "Input should be a multiple of {multiple_of}")]
178184
FloatMultipleOf {
179185
multiple_of: f64,
180186
},
181-
#[strum(serialize = "greater_than", message = "Value must be greater than {gt}")]
187+
#[strum(serialize = "greater_than", message = "Input should be greater than {gt}")]
182188
FloatGreaterThan {
183189
gt: f64,
184190
},
185191
#[strum(
186192
serialize = "greater_than_equal",
187-
message = "Value must be greater than or equal to {ge}"
193+
message = "Input should be greater than or equal to {ge}"
188194
)]
189195
FloatGreaterThanEqual {
190196
ge: f64,
191197
},
192-
#[strum(serialize = "less_than", message = "Value must be less than {lt}")]
198+
#[strum(serialize = "less_than", message = "Input should be less than {lt}")]
193199
FloatLessThan {
194200
lt: f64,
195201
},
196-
#[strum(serialize = "less_than_equal", message = "Value must be less than or equal to {le}")]
202+
#[strum(
203+
serialize = "less_than_equal",
204+
message = "Input should be less than or equal to {le}"
205+
)]
197206
FloatLessThanEqual {
198207
le: f64,
199208
},
200209
// ---------------------
201210
// bytes errors
202-
#[strum(message = "Value must be a valid bytes")]
211+
#[strum(message = "Input should be a valid bytes")]
203212
BytesType,
204-
#[strum(message = "Data must have at least {min_length} bytes", serialize = "too_short")]
213+
#[strum(message = "Data should have at least {min_length} bytes", serialize = "too_short")]
205214
BytesTooShort {
206215
min_length: usize,
207216
},
208-
#[strum(message = "Data must have at most {max_length} bytes", serialize = "too_long")]
217+
#[strum(message = "Data should have at most {max_length} bytes", serialize = "too_long")]
209218
BytesTooLong {
210219
max_length: usize,
211220
},
@@ -225,41 +234,44 @@ pub enum ErrorKind {
225234
},
226235
// ---------------------
227236
// literals
228-
#[strum(serialize = "literal_error", message = "Value must be {expected}")]
237+
#[strum(serialize = "literal_error", message = "Input should be {expected}")]
229238
LiteralSingleError {
230239
expected: String,
231240
},
232-
#[strum(serialize = "literal_error", message = "Value must be one of: {expected}")]
241+
#[strum(serialize = "literal_error", message = "Input should be one of: {expected}")]
233242
LiteralMultipleError {
234243
expected: String,
235244
},
236245
// ---------------------
237246
// date errors
238-
#[strum(message = "Value must be a valid date")]
247+
#[strum(message = "Input should be a valid date")]
239248
DateType,
240-
#[strum(message = "Value must be a valid date in the format YYYY-MM-DD, {error}")]
249+
#[strum(message = "Input should be a valid date in the format YYYY-MM-DD, {error}")]
241250
DateParsing {
242251
error: &'static str,
243252
},
244-
#[strum(message = "Value must be a valid date or datetime, {error}")]
253+
#[strum(message = "Input should be a valid date or datetime, {error}")]
245254
DateFromDatetimeParsing {
246255
error: String,
247256
},
248-
#[strum(message = "Datetimes provided to dates must have zero time - e.g. be exact dates")]
257+
#[strum(message = "Datetimes provided to dates should have zero time - e.g. be exact dates")]
249258
DateFromDatetimeInexact,
250259
// ---------------------
251260
// date errors
252-
#[strum(message = "Value must be a valid time")]
261+
#[strum(message = "Input should be a valid time")]
253262
TimeType,
254-
#[strum(message = "Value must be in a valid time format, {error}")]
263+
#[strum(message = "Input should be in a valid time format, {error}")]
255264
TimeParsing {
256265
error: &'static str,
257266
},
258267
// ---------------------
259268
// datetime errors
260-
#[strum(serialize = "datetime_type", message = "Value must be a valid datetime")]
269+
#[strum(serialize = "datetime_type", message = "Input should be a valid datetime")]
261270
DateTimeType,
262-
#[strum(serialize = "datetime_parsing", message = "Value must be a valid datetime, {error}")]
271+
#[strum(
272+
serialize = "datetime_parsing",
273+
message = "Input should be a valid datetime, {error}"
274+
)]
263275
DateTimeParsing {
264276
error: &'static str,
265277
},
@@ -272,23 +284,23 @@ pub enum ErrorKind {
272284
},
273285
// ---------------------
274286
// timedelta errors
275-
#[strum(message = "Value must be a valid timedelta")]
287+
#[strum(message = "Input should be a valid timedelta")]
276288
TimeDeltaType,
277-
#[strum(message = "Value must be a valid timedelta, {error}")]
289+
#[strum(message = "Input should be a valid timedelta, {error}")]
278290
TimeDeltaParsing {
279291
error: &'static str,
280292
},
281293
// ---------------------
282294
// frozenset errors
283-
#[strum(message = "Value must be a valid frozenset")]
295+
#[strum(message = "Input should be a valid frozenset")]
284296
FrozenSetType,
285297
// ---------------------
286298
// introspection types - e.g. isinstance, callable
287-
#[strum(message = "Input must be an instance of {class}")]
299+
#[strum(message = "Input should be an instance of {class}")]
288300
IsInstanceOf {
289301
class: String,
290302
},
291-
#[strum(message = "Input must be callable")]
303+
#[strum(message = "Input should be callable")]
292304
CallableType,
293305
// ---------------------
294306
// union errors

src/input/datetime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ pub fn int_as_time<'a>(
331331
t if t < 0_i64 => {
332332
return Err(ValError::new(
333333
ErrorKind::TimeParsing {
334-
error: "time in seconds must be positive",
334+
error: "time in seconds should be positive",
335335
},
336336
input,
337337
));

src/lookup_key.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl LookupKey {
6060
let list: &PyList = value.cast_as()?;
6161
let first = match list.get_item(0) {
6262
Ok(v) => v,
63-
Err(_) => return py_error!("Lookup paths must have at least one element"),
63+
Err(_) => return py_error!("Lookup paths should have at least one element"),
6464
};
6565
let mut locs: Vec<Path> = if first.cast_as::<PyString>().is_ok() {
6666
// list of strings rather than list of lists
@@ -91,7 +91,7 @@ impl LookupKey {
9191
.collect::<PyResult<Path>>()?;
9292

9393
if path.is_empty() {
94-
py_error!("Each alias path must have at least one element")
94+
py_error!("Each alias path should have at least one element")
9595
} else {
9696
Ok(path)
9797
}
@@ -181,7 +181,7 @@ impl LookupKey {
181181
let mut path_iter = path.iter();
182182

183183
// first step is different from the rest as we already know dict is JsonObject
184-
// because of above checks, we know that path must have at least one element, hence unwrap
184+
// because of above checks, we know that path should have at least one element, hence unwrap
185185
let v: &JsonInput = match path_iter.next().unwrap().json_obj_get(dict) {
186186
Some(v) => v,
187187
None => continue,
@@ -244,7 +244,7 @@ impl PathItem {
244244
} else {
245245
let int_key = obj.extract::<usize>()?;
246246
if index == 0 {
247-
py_error!(PyTypeError; "The first item in an alias path must be a string")
247+
py_error!(PyTypeError; "The first item in an alias path should be a string")
248248
} else {
249249
Ok(Self::I(int_key))
250250
}

src/validators/literal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl BuildValidator for LiteralBuilder {
2626
) -> PyResult<CombinedValidator> {
2727
let expected: &PyList = schema.get_as_req(intern!(schema.py(), "expected"))?;
2828
if expected.is_empty() {
29-
return py_error!(r#""expected" must have length > 0"#);
29+
return py_error!(r#""expected" should have length > 0"#);
3030
} else if expected.len() == 1 {
3131
let first = expected.get_item(0)?;
3232
if let Ok(str) = first.extract::<String>() {

src/validators/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ fn parse_json(input: &PyAny) -> PyResult<serde_json::Result<JsonInput>> {
237237
Ok(serde_json::from_slice(unsafe { py_byte_array.as_bytes() }))
238238
} else {
239239
let input_type = input.get_type().name().unwrap_or("unknown");
240-
py_error!(PyTypeError; "JSON input must be str, bytes or bytearray, not {}", input_type)
240+
py_error!(PyTypeError; "JSON input should be str, bytes or bytearray, not {}", input_type)
241241
}
242242
}
243243

0 commit comments

Comments
 (0)