8000 fix clippy lints for Rust 1.86 (#1682) · pydantic/pydantic-core@ee8c173 · GitHub
[go: up one dir, main page]

Skip to content

Commit ee8c173

Browse files
authored
fix clippy lints for Rust 1.86 (#1682)
1 parent baa8cbf commit ee8c173

File tree

16 files changed

+31
-31
lines changed

16 files changed

+31
-31
lines changed

src/errors/location.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl Location {
147147
Self::Empty => {
148148
*self = Self::new_some(loc_item);
149149
}
150-
};
150+
}
151151
}
152152
}
153153

src/input/datetime.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use speedate::MicrosecondsPrecisionOverflowBehavior;
1010
use speedate::{Date, DateTime, Duration, ParseError, Time, TimeConfig};
1111
use std::borrow::Cow;
1212
use std::collections::hash_map::DefaultHasher;
13+
use std::fmt::Write;
1314
use std::hash::Hash;
1415
use std::hash::Hasher;
1516

@@ -59,7 +60,7 @@ impl<'py> EitherDate<'py> {
5960
},
6061
input,
6162
));
62-
};
63+
}
6364
let py_date = PyDate::new(py, date.year.into(), date.month, date.day)?;
6465
Ok(py_date.into())
6566
}
@@ -296,7 +297,7 @@ impl<'py> EitherDateTime<'py> {
296297
},
297298
input,
298299
));
299-
};
300+
}
300301
let py_dt = PyDateTime::new(
301302
py,
302303
dt.date.year.into(),
@@ -590,7 +591,7 @@ impl TzInfo {
590591
);
591592

592593
if seconds != 0 {
593-
result.push_str(&format!(":{:02}", seconds.abs()));
594+
write!(result, ":{:02}", seconds.abs()).expect("writing to string should never fail");
594595
}
595596

596597
result

src/input/shared.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ fn strip_leading_zeros(s: &str) -> Option<&str> {
181181
Some((_, c)) if ('1'..='9').contains(&c) || c == '-' => return Some(s),
182182
// anything else is invalid, we return None
183183
_ => return None,
184-
};
184+
}
185185
for (i, c) in char_iter {
186186
match c {
187187
// continue on more leading zeros or if we get an underscore we continue - we're "within the number"

src/serializers/errors.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::fmt;
2+
use std::fmt::Write;
23

34
use pyo3::exceptions::PyValueError;
45
use pyo3::prelude::*;
@@ -154,7 +155,7 @@ impl PydanticSerializationUnexpectedValue {
154155
if !message.is_empty() {
155156
message.push_str(": ");
156157
}
157-
message.push_str(&format!("Expected `{field_type}`"));
158+
write!(message, "Expected `{field_type}`").expect("writing to string should never fail");
158159
if self.input_value.is_some() {
159160
message.push_str(" - serialized value may not be as expected");
160161
}
@@ -170,7 +171,8 @@ impl PydanticSerializationUnexpectedValue {
170171

171172
let value_str = truncate_safe_repr(bound_input, None);
172173

173-
message.push_str(&format!(" [input_value={value_str}, input_type={input_type}]"));
174+
write!(message, " [input_value={value_str}, input_type={input_type}]")
175+
.expect("writing to string should never fail");
174176
}
175177

176178
if message.is_empty() {

src/serializers/type_serializers/generator.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,7 @@ impl TypeSerializer for GeneratorSerializer {
115115
) -> Result<S::Ok, S::Error> {
116116
match value.downcast::<PyIterator>() {
117117
Ok(py_iter) => {
118-
let len = match value.len() {
119-
Ok(len) => Some(len),
120-
Err(_) => None,
121-
};
118+
let len = value.len().ok();
122119
let mut seq = serializer.serialize_seq(len)?;
123120
let item_serializer = self.item_serializer.as_ref();
124121

src/serializers/type_serializers/tuple.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,10 @@ impl TupleSerializer {
243243
serializer: &CombinedSerializer::Any(AnySerializer),
244244
}) {
245245
return Ok(Err(e));
246-
};
246+
}
247247
}
248248
}
249-
};
249+
}
250250
Ok(Ok(()))
251251
}
252252
}

src/url.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ impl PyMultiHostUrl {
392392
multi_url.push_str(&single_host.to_string());
393393
if index != hosts.len() - 1 {
394394
multi_url.push(',');
395-
};
395+
}
396396
}
397397
multi_url
398398
} else if host.is_some() {
@@ -456,7 +456,7 @@ impl fmt::Display for UrlHostParts {
456456
(None, Some(password)) => write!(f, ":{password}@")?,
457457
(Some(username), Some(password)) => write!(f, "{username}:{password}@")?,
458458
(None, None) => {}
459-
};
459+
}
460460
if let Some(host) = &self.host {
461461
write!(f, "{host}")?;
462462
}

src/validators/arguments.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl Validator for ArgumentsValidator {
280280
input,
281281
index,
282282
));
283-
};
283+
}
284284
}
285285
}
286286
}

src/validators/dataclass.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ impl Validator for DataclassArgsValidator {
190190
// We could try to "fix" this in the future if desired.
191191
Err(ValError::LineErrors(line_errors)) => errors.extend(line_errors),
192192
Err(err) => return Err(err),
193-
};
193+
}
194194
continue;
195-
};
195+
}
196196

197197
let mut pos_value = None;
198198
if let Some(args) = args.args() {
@@ -265,7 +265,7 @@ impl Validator for DataclassArgsValidator {
265265
&field.name,
266266
));
267267
}
268-
Err(ValError::Omit) => continue,
268+
Err(ValError::Omit) => {}
269269
Err(ValError::LineErrors(line_errors)) => {
270270
for err in line_errors {
271271
// Note: this will always use the field name even if there is an alias

src/validators/decimal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl Validator for DecimalValidator {
194194
}
195195
}
196196
}
197-
};
197+
}
198198
}
199199
}
200200

src/validators/literal.rs

179B Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,15 @@ impl<T: Debug> LiteralLookup<T> {
158158
let id: usize = v.extract().unwrap();
159159
return Ok(Some((input, &self.values[id])));
160160
}
161-
};
161+
}
162162
if let Some(expected_py_values) = &self.expected_py_values {
163163
let py_input = get_py_input()?;
164164
for (k, id) in expected_py_values {
165165
if k.bind(py).eq(py_input).unwrap_or(false) {
166166
return Ok(Some((input, &self.values[*id])));
167167
}
168168
}
169-
};
169+
}
170170

171171
// this one must be last to avoid conflicts with the other lookups, think of this
172172
// almost as a lax fallback
@@ -179,7 +179,7 @@ impl<T: Debug> LiteralLookup<T> {
179179
let id: usize = v.extract().unwrap();
180180
return Ok(Some((input, &self.values[id])));
181181
}
182-
};
182+
}
183183
Ok(None)
184184
}
185185

src/validators/model_fields.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl Validator for ModelFieldsValidator {
228228
&field.name,
229229
));
230230
}
231-
Err(ValError::Omit) => continue,
231+
Err(ValError::Omit) => {}
232232
Err(ValError::LineErrors(line_errors)) => {
233233
for err in line_errors {
234234
// Note: this will always use the field name even if there is an alias
@@ -334,7 +334,7 @@ impl Validator for ModelFieldsValidator {
334334
} else {
335335
model_extra_dict.set_item(&py_key, value.to_object(self.py)?)?;
336336
self.fields_set_vec.push(py_key.into());
337-
};
337+
}
338338
}
339339
}
340340
}
@@ -368,7 +368,7 @@ impl Validator for ModelFieldsValidator {
368368
// from attributes, set it now so __pydantic_extra__ is always a dict if extra=allow
369369
if matches!(self.extra_behavior, ExtraBehavior::Allow) && model_extra_dict_op.is_none() {
370370
model_extra_dict_op = Some(PyDict::new(py));
371-
};
371+
}
372372

373373
Ok((model_dict, model_extra_dict_op, fields_set).into_py_any(py)?)
374374
}

src/validators/typed_dict.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl Validator for TypedDictValidator {
252252
));
253253
}
254254
}
255-
Err(ValError::Omit) => continue,
255+
Err(ValError::Omit) => {}
256256
Err(ValError::LineErrors(line_errors)) => {
257257
for err in line_errors {
258258
// Note: this will always use the field name even if there is an alias
@@ -347,7 +347,7 @@ impl Validator for TypedDictValidator {
347347
}
348348
} else {
349349
self.output_dict.set_item(py_key, value.to_object(self.py)?)?;
350-
};
350+
}
351351
}
352352
}
353353
}

src/validators/union.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl UnionValidator {
193193
match validator.validate(py, input, state) {
194194
Err(ValError::LineErrors(lines)) => errors.push(validator, label.as_deref(), lines),
195195
otherwise => return otherwise,
196-
};
196+
}
197197
}
198198

199199
Err(errors.into_val_error(input))

src/validators/url.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ fn parse_multihost_url<'py>(
392392
'\t' | '\n' | '\r' => (),
393393
c if c <= &' ' => (),
394394
_ => break,
395-
};
395+
}
396396
chars.next();
397397
} else {
398398
break;

src/validators/uuid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ impl UuidValidator {
215215
input,
216216
));
217217
}
218-
};
218+
}
219219
Ok(uuid)
220220
}
221221

0 commit comments

Comments
 (0)
0