Skip to content

Commit a50ca74

Browse files
committed
empty vm/functin/mod.rs
1 parent 580bcb5 commit a50ca74

File tree

2 files changed

+33
-37
lines changed

2 files changed

+33
-37
lines changed

vm/src/anystr.rs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::{
2-
builtins::PyIntRef,
2+
builtins::{PyIntRef, PyTupleRef},
33
cformat::CFormatString,
4-
function::{single_or_tuple_any, OptionalOption},
4+
function::OptionalOption,
55
protocol::PyIterIter,
6-
AsObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine,
6+
AsObject, PyObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine,
77
};
88
use num_traits::{cast::ToPrimitive, sign::Signed};
99
use std::str::FromStr;
@@ -441,3 +441,33 @@ pub trait AnyStr<'s>: 's {
441441
.format(vm, values)
442442
}
443443
}
444+
445+
/// Tests that the predicate is True on a single value, or if the value is a tuple a tuple, then
446+
/// test that any of the values contained within the tuples satisfies the predicate. Type parameter
447+
/// T specifies the type that is expected, if the input value is not of that type or a tuple of
448+
/// values of that type, then a TypeError is raised.
449+
pub fn single_or_tuple_any<T, F, M>(
450+
obj: PyObjectRef,
451+
predicate: &F,
452+
message: &M,
453+
vm: &VirtualMachine,
454+
) -> PyResult<bool>
455+
where
456+
T: TryFromObject,
457+
F: Fn(&T) -> PyResult<bool>,
458+
M: Fn(&PyObject) -> String,
459+
{
460+
match T::try_from_object(vm, obj.clone()) {
461+
Ok(single) => (predicate)(&single),
462+
Err(_) => {
463+
let tuple = PyTupleRef::try_from_object(vm, obj.clone())
464+
.map_err(|_| vm.new_type_error((message)(&obj)))?;
465+
for obj in &tuple {
466+
if single_or_tuple_any(obj.clone(), predicate, message, vm)? {
467+
return Ok(true);
468+
}
469+
}
470+
Ok(false)
471+
}
472+
}
473+
}

vm/src/function/mod.rs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,3 @@ pub use builtin::{IntoPyNativeFunc, OwnedParam, PyNativeFunc, RefParam};
1616
pub use either::Either;
1717
pub use number::{ArgIntoBool, ArgIntoComplex, ArgIntoFloat};
1818
pub use protocol::{ArgCallable, ArgIterable, ArgMapping, ArgSequence};
19-
20-
use crate::{
21-
builtins::PyTupleRef, convert::TryFromObject, PyObject, PyObjectRef, PyResult, VirtualMachine,
22-
};
23-
24-
/// Tests that the predicate is True on a single value, or if the value is a tuple a tuple, then
25-
/// test that any of the values contained within the tuples satisfies the predicate. Type parameter
26-
/// T specifies the type that is expected, if the input value is not of that type or a tuple of
27-
/// values of that type, then a TypeError is raised.
28-
pub fn single_or_tuple_any<T, F, M>(
29-
obj: PyObjectRef,
30-
predicate: &F,
31-
message: &M,
32-
vm: &VirtualMachine,
33-
) -> PyResult<bool>
34-
where
35-
T: TryFromObject,
36-
F: Fn(&T) -> PyResult<bool>,
37-
M: Fn(&PyObject) -> String,
38-
{
39-
match T::try_from_object(vm, obj.clone()) {
40-
Ok(single) => (predicate)(&single),
41-
Err(_) => {
42-
let tuple = PyTupleRef::try_from_object(vm, obj.clone())
43-
.map_err(|_| vm.new_type_error((message)(&obj)))?;
44-
for obj in &tuple {
45-
if single_or_tuple_any(obj.clone(), predicate, message, vm)? {
46-
return Ok(true);
47-
}
48-
}
49-
Ok(false)
50-
}
51-
}
52-
}

0 commit comments

Comments
 (0)