Skip to content

Commit a0cb1f5

Browse files
committed
Remove dead code
1 parent a0f00d1 commit a0cb1f5

File tree

12 files changed

+216
-548
lines changed

12 files changed

+216
-548
lines changed

src/input/input_abstract.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{PyMultiHostUrl, PyUrl};
99
use super::datetime::{EitherDate, EitherDateTime, EitherTime, EitherTimedelta};
1010
use super::generic_iterable::GenericIterable;
1111
use super::return_enums::{EitherBytes, EitherString};
12-
use super::{GenericArguments, GenericCollection, GenericIterator, GenericMapping, JsonInput};
12+
use super::{GenericArguments, GenericIterator, GenericMapping, JsonInput};
1313

1414
#[derive(Debug, Clone, Copy)]
1515
pub enum InputType {
@@ -169,19 +169,6 @@ pub trait Input<'a>: fmt::Debug + ToPyObject {
169169

170170
fn extract_iterable(&'a self) -> ValResult<GenericIterable<'a>>;
171171

172-
fn validate_tuple(&'a self, strict: bool) -> ValResult<GenericCollection<'a>> {
173-
if strict {
174-
self.strict_tuple()
175-
} else {
176-
self.lax_tuple()
177-
}
178-
}
179-
fn strict_tuple(&'a self) -> ValResult<GenericCollection<'a>>;
180-
#[cfg_attr(has_no_coverage, no_coverage)]
181-
fn lax_tuple(&'a self) -> ValResult<GenericCollection<'a>> {
182-
self.strict_tuple()
183-
}
184-
185172
fn validate_iter(&self) -> ValResult<GenericIterator>;
186173

187174
fn validate_date(&self, strict: bool) -> ValResult<EitherDate> {

src/input/input_json.rs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use super::datetime::{
1010
use super::parse_json::JsonArray;
1111
use super::shared::{float_as_int, int_as_bool, map_json_err, str_as_bool, str_as_int};
1212
use super::{
13-
EitherBytes, EitherString, EitherTimedelta, GenericArguments, GenericCollection, GenericIterator, GenericMapping,
14-
Input, JsonArgs, JsonInput,
13+
EitherBytes, EitherString, EitherTimedelta, GenericArguments, GenericIterator, GenericMapping, Input, JsonArgs,
14+
JsonInput,
1515
};
1616

1717
impl<'a> Input<'a> for JsonInput {
@@ -187,18 +187,6 @@ impl<'a> Input<'a> for JsonInput {
187187
self.validate_dict(false)
188188
}
189189

190-
fn validate_tuple(&'a self, _strict: bool) -> ValResult<GenericCollection<'a>> {
191-
// just as in set's case, List has to be allowed
192-
match self {
193-
JsonInput::Array(a) => Ok(a.into()),
194-
_ => Err(ValError::new(ErrorType::TupleType, self)),
195-
}
196-
}
197-
#[cfg_attr(has_no_coverage, no_coverage)]
198-
fn strict_tuple(&'a self) -> ValResult<GenericCollection<'a>> {
199-
self.validate_tuple(false)
200-
}
201-
202190
fn extract_iterable(&'a self) -> ValResult<super::generic_iterable::GenericIterable<'a>> {
203191
match self {
204192
JsonInput::Array(a) => Ok(super::generic_iterable::GenericIterable::JsonArray(a)),
@@ -381,15 +369,6 @@ impl<'a> Input<'a> for String {
381369
Err(ValError::new(ErrorType::IterableType, self))
382370
}
383371

384-
#[cfg_attr(has_no_coverage, no_coverage)]
385-
fn validate_tuple(&'a self, _strict: bool) -> ValResult<GenericCollection<'a>> {
386-
Err(ValError::new(ErrorType::TupleType, self))
387-
}
388-
#[cfg_attr(has_no_coverage, no_coverage)]
389-
fn strict_tuple(&'a self) -> ValResult<GenericCollection<'a>> {
390-
self.validate_tuple(false)
391-
}
392-
393372
fn validate_iter(&self) -> ValResult<GenericIterator> {
394373
Ok(string_to_vec(self).into())
395374
}

src/input/input_python.rs

Lines changed: 2 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -23,39 +23,10 @@ use super::datetime::{
2323
};
2424
use super::shared::{float_as_int, int_as_bool, map_json_err, str_as_bool, str_as_int};
2525
use super::{
26-
py_string_str, EitherBytes, EitherString, EitherTimedelta, GenericArguments, GenericCollection, GenericIterator,
27-
GenericMapping, Input, JsonInput, PyArgs,
26+
py_string_str, EitherBytes, EitherString, EitherTimedelta, GenericArguments, GenericIterator, GenericMapping,
27+
Input, JsonInput, PyArgs,
2828
};
2929

30-
/// Extract generators and deques into a `GenericCollection`
31-
macro_rules! extract_shared_iter {
32-
($type:ty, $obj:ident) => {
33-
if $obj.downcast::<PyIterator>().is_ok() {
34-
Some($obj.into())
35-
} else if is_deque($obj) {
36-
Some($obj.into())
37-
} else {
38-
None
39-
}
40-
};
41-
}
42-
43-
/// Extract dict keys, values and items into a `GenericCollection`
44-
#[cfg(not(PyPy))]
45-
macro_rules! extract_dict_iter {
46-
($obj:ident) => {
47-
if $obj.is_instance_of::<PyDictKeys>().unwrap_or(false) {
48-
Some($obj.into())
49-
} else if $obj.is_instance_of::<PyDictValues>().unwrap_or(false) {
50-
Some($obj.into())
51-
} else if $obj.is_instance_of::<PyDictItems>().unwrap_or(false) {
52-
Some($obj.into())
53-
} else {
54-
None
55-
}
56-
};
57-
}
58-
5930
#[cfg(PyPy)]
6031
macro_rules! extract_dict_iter {
6132
($obj:ident) => {
@@ -71,7 +42,6 @@ macro_rules! extract_dict_iter {
7142
};
7243
}
7344

74-
/// Extract dict keys, values and items into a `GenericCollection`
7545
#[cfg(not(PyPy))]
7646
macro_rules! extract_dict_keys {
7747
($py:expr, $obj:ident) => {
@@ -437,28 +407,6 @@ impl<'a> Input<'a> for PyAny {
437407
}
438408
}
439409

440-
fn strict_tuple(&'a self) -> ValResult<GenericCollection<'a>> {
441-
if let Ok(tuple) = self.downcast::<PyTuple>() {
442-
Ok(tuple.into())
443-
} else {
444-
Err(ValError::new(ErrorType::TupleType, self))
445-
}
446-
}
447-
448-
fn lax_tuple(&'a self) -> ValResult<GenericCollection<'a>> {
449-
if let Ok(tuple) = self.downcast::<PyTuple>() {
450-
Ok(tuple.into())
451-
} else if let Ok(list) = self.downcast::<PyList>() {
452-
Ok(list.into())
453-
} else if let Some(collection) = extract_dict_iter!(self) {
454-
Ok(collection)
455-
} else if let Some(collection) = extract_shared_iter!(PyTuple, self) {
456-
Ok(collection)
457-
} else {
458-
Err(ValError::new(ErrorType::TupleType, self))
459-
}
460-
}
461-
462410
fn extract_iterable(&'a self) -> ValResult<super::generic_iterable::GenericIterable<'a>> {
463411
// Handle concrete non-overlapping types first, then abstract types
464412
if let Ok(iterable) = self.downcast::<PyList>() {
@@ -644,21 +592,6 @@ fn maybe_as_string(v: &PyAny, unicode_error: ErrorType) -> ValResult<Option<Cow<
644592
}
645593
}
646594

647-
static DEQUE_TYPE: GILOnceCell<Py<PyType>> = GILOnceCell::new();
648-
649-
fn is_deque(v: &PyAny) -> bool {
650-
let py = v.py();
651-
let deque_type = DEQUE_TYPE
652-
.get_or_init(py, || import_type(py, "collections", "deque").unwrap())
653-
.as_ref(py);
654-
v.is_instance(deque_type).unwrap_or(false)
655-
}
656-
657-
fn import_type(py: Python, module: &str, attr: &str) -> PyResult<Py<PyType>> {
658-
let obj = py.import(module)?.getattr(attr)?;
659-
Ok(obj.downcast::<PyType>()?.into())
660-
}
661-
662595
fn is_builtin_str(py_str: &PyString) -> bool {
663596
py_str.get_type().is(PyString::type_object(py_str.py()))
664597
}

src/input/iterator.rs

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::{marker::PhantomData, mem};
2-
31
use pyo3::{PyObject, PyResult, Python};
42

53
use super::Input;
@@ -36,17 +34,18 @@ impl IterableValidatorBuilder {
3634
fail_fast,
3735
}
3836
}
39-
pub fn build<'data, 'py, I, R, L, V, D, N>(
37+
pub fn build<'data, I, R, L, V, D, N>(
4038
self,
4139
iter: I,
4240
validation_func: V,
4341
input: &'data D,
44-
) -> IterableValidator<'data, 'py, I, R, L, V, D, N>
42+
) -> IterableValidator<'data, I, R, L, V, D, N>
4543
where
46-
L: Into<LocItem>,
47-
V: FnMut(Python<'py>, &L, R) -> ValResult<'data, N>,
44+
L: Into<LocItem> + std::fmt::Debug,
45+
V: FnMut(Python<'data>, &L, R) -> ValResult<'data, N>,
4846
I: Iterator<Item = ValResult<'data, (L, R)>>,
4947
D: Input<'data>,
48+
R: std::fmt::Debug,
5049
{
5150
IterableValidator::new(
5251
iter,
@@ -60,12 +59,13 @@ impl IterableValidatorBuilder {
6059
}
6160

6261
// Almost like an Iterator, but accepts some extra arguments
63-
pub struct IterableValidator<'data, 'py: 'data, I, R, L, V, D, N>
62+
pub struct IterableValidator<'data, I, R, L, V, D, N>
6463
where
6564
L: Into<LocItem>,
66-
V: FnMut(Python<'py>, &L, R) -> ValResult<'data, N>,
65+
V: FnMut(Python<'data>, &L, R) -> ValResult<'data, N>,
6766
I: Iterator<Item = ValResult<'data, (L, R)>>,
6867
D: Input<'data>,
68+
R: std::fmt::Debug,
6969
{
7070
iter: I,
7171
validation_func: V,
@@ -76,15 +76,15 @@ where
7676
errors: Vec<ValLineError<'data>>,
7777
done: bool,
7878
current_index: usize,
79-
p: PhantomData<Python<'py>>,
8079
}
8180

82-
impl<'data, 'py, I, R, L, V, D, N> IterableValidator<'data, 'py, I, R, L, V, D, N>
81+
impl<'data, I, R, L, V, D, N> IterableValidator<'data, I, R, L, V, D, N>
8382
where
84-
L: Into<LocItem>,
85-
V: FnMut(Python<'py>, &L, R) -> ValResult<'data, N>,
83+
L: Into<LocItem> + std::fmt::Debug,
84+
V: FnMut(Python<'data>, &L, R) -> ValResult<'data, N>,
8685
I: Iterator<Item = ValResult<'data, (L, R)>>,
8786
D: Input<'data>,
87+
R: std::fmt::Debug,
8888
{
8989
fn check_max_length(&self, current_length: usize, max_length: Option<usize>) -> ValResult<'data, ()> {
9090
if let Some(max_length) = max_length {
@@ -126,10 +126,9 @@ where
126126
errors: vec![],
127127
done: false,
128128
current_index: 0,
129-
p: PhantomData,
130129
}
131130
}
132-
pub fn next(&mut self, py: Python<'py>, current_output_length: usize) -> Option<ValResult<'data, (L, N)>> {
131+
pub fn next(&mut self, py: Python<'data>, current_output_length: usize) -> Option<ValResult<'data, (L, N)>> {
133132
if self.done {
134133
return None;
135134
}
@@ -145,23 +144,25 @@ where
145144
self.current_index += 1;
146145
match self.iter.next() {
147146
None => {
148-
if self.errors.is_empty() {
149-
// check min len and return
150-
if let Some(min_length) = self.length_constraints.min_length {
151-
if min_length > current_output_length {
152-
return Some(Err(ValError::new(
153-
ErrorType::TooShort {
154-
field_type: self.field_type.to_string(),
155-
min_length,
156-
actual_length: current_output_length,
157-
},
158-
self.input,
159-
)));
160-
}
147+
self.done = true;
148+
// check min len and return
149+
if let Some(min_length) = self.length_constraints.min_length {
150+
if min_length > current_output_length {
151+
let err = ValLineError::new(
152+
ErrorType::TooShort {
153+
field_type: self.field_type.to_string(),
154+
min_length,
155+
actual_length: current_output_length,
156+
},
157+
self.input,
158+
);
159+
self.errors.push(err);
161160
}
161+
}
162+
if self.errors.is_empty() {
162163
return None;
163164
}
164-
return Some(Err(ValError::LineErrors(mem::replace(&mut self.errors, vec![]))));
165+
return Some(Err(ValError::LineErrors(std::mem::take(&mut self.errors))));
165166
}
166167
Some(iter_result) => match iter_result {
167168
Ok((loc, item)) => match (self.validation_func)(py, &loc, item) {
@@ -202,16 +203,17 @@ where
202203
}
203204
}
204205

205-
pub fn validate_into_vec<'data, 'py, I, R, L, V, D, N>(
206-
py: Python<'py>,
206+
pub fn validate_into_vec<'data, I, R, L, V, D, N>(
207+
py: Python<'data>,
207208
capacity: usize,
208-
iterator: &mut IterableValidator<'data, 'py, I, R, L, V, D, N>,
209+
iterator: &mut IterableValidator<'data, I, R, L, V, D, N>,
209210
) -> ValResult<'data, Vec<N>>
210211
where
211-
L: Into<LocItem>,
212-
V: FnMut(Python<'py>, &L, R) -> ValResult<'data, N>,
212+
L: Into<LocItem> + std::fmt::Debug,
213+
V: FnMut(Python<'data>, &L, R) -> ValResult<'data, N>,
213214
I: Iterator<Item = ValResult<'data, (L, R)>>,
214215
D: Input<'data>,
216+
R: std::fmt::Debug,
215217
{
216218
let mut output = Vec::with_capacity(capacity);
217219
while let Some(result) = iterator.next(py, output.len()) {
@@ -314,7 +316,6 @@ where
314316
}
315317
}
316318

317-
318319
/// Utility wrapper used by dicts and mappings
319320
#[allow(clippy::too_many_arguments)]
320321
pub fn validate_mapping<'s, 'data, I, V, E, O, S>(

src/input/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ pub(crate) use input_abstract::{Input, InputType};
2121
pub(crate) use parse_json::{JsonInput, JsonObject};
2222
pub(crate) use return_enums::{
2323
py_string_str, AttributesGenericIterator, DictGenericIterator, EitherBytes, EitherString, GenericArguments,
24-
GenericCollection, GenericIterator, GenericMapping, JsonArgs, JsonObjectGenericIterator, MappingGenericIterator,
25-
PyArgs,
24+
GenericIterator, GenericMapping, JsonArgs, JsonObjectGenericIterator, MappingGenericIterator, PyArgs,
2625
};
2726

2827
// Defined here as it's not exported by pyo3

0 commit comments

Comments
 (0)