Skip to content

Commit 374ab55

Browse files
committed
MNT: expose internal helper isiterable
Move it to srreal_validators.cpp.
1 parent 24cdbd6 commit 374ab55

3 files changed

Lines changed: 16 additions & 13 deletions

File tree

src/extensions/srreal_converters.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <diffpy/srreal/StructureAdapter.hpp>
3232

3333
#include "srreal_converters.hpp"
34+
#include "srreal_validators.hpp"
3435

3536
#include "srreal_numpy_symbol.hpp"
3637
// numpy/arrayobject.h needs to be included after srreal_numpy_symbol.hpp,
@@ -73,19 +74,6 @@ boost::python::object newNumPyArray(int dim, const int* sz, int typenum)
7374
return rv;
7475
}
7576

76-
77-
bool isiterable(boost::python::object obj)
78-
{
79-
using namespace boost::python;
80-
#if PY_MAJOR_VERSION >= 3
81-
object Iterable = import("collections.abc").attr("Iterable");
82-
#else
83-
object Iterable = import("collections").attr("Iterable");
84-
#endif
85-
bool rv = (1 == PyObject_IsInstance(obj.ptr(), Iterable.ptr()));
86-
return rv;
87-
}
88-
8977
} // namespace
9078

9179
namespace srrealmodule {

src/extensions/srreal_validators.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*****************************************************************************/
1818

1919
#include <boost/python/errors.hpp>
20+
#include <boost/python/import.hpp>
2021

2122
#include "srreal_validators.hpp"
2223

@@ -43,6 +44,19 @@ void ensure_non_negative(int value)
4344
}
4445
}
4546

47+
48+
bool isiterable(boost::python::object obj)
49+
{
50+
using boost::python::import;
51+
#if PY_MAJOR_VERSION >= 3
52+
object Iterable = import("collections.abc").attr("Iterable");
53+
#else
54+
object Iterable = import("collections").attr("Iterable");
55+
#endif
56+
bool rv = (1 == PyObject_IsInstance(obj.ptr(), Iterable.ptr()));
57+
return rv;
58+
}
59+
4660
} // namespace srrealmodule
4761

4862
// End of file

src/extensions/srreal_validators.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace srrealmodule {
2323

2424
void ensure_index_bounds(int idx, int lo, int hi);
2525
void ensure_non_negative(int value);
26+
bool isiterable(boost::python::object obj);
2627

2728
} // namespace srrealmodule
2829

0 commit comments

Comments
 (0)