Skip to content

Commit c1564c0

Browse files
committed
Type Check for filepath argument
1 parent 50b323d commit c1564c0

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/binding/python/Series.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* If not, see <http://www.gnu.org/licenses/>.
2020
*/
2121
#include "openPMD/Series.hpp"
22+
#include "openPMD/Error.hpp"
2223
#include "openPMD/IO/Access.hpp"
2324
#include "openPMD/Iteration.hpp"
2425
#include "openPMD/IterationEncoding.hpp"
@@ -104,6 +105,14 @@ struct DefineSeriesConstructorPerPathType
104105
static auto filepath_as_string(py::object const &path) -> std::string
105106
{
106107
auto casted = path.attr("__str__")();
108+
auto type_repr = py::repr(path).cast<std::string>();
109+
if (type_repr.substr(0, 9) != "PosixPath" &&
110+
type_repr.substr(0, 11) != "WindowsPath")
111+
{
112+
throw error::WrongAPIUsage(
113+
"openpmd.Series constructor: 'filepath' argument may either be "
114+
"a String or pathlib.Path.");
115+
}
107116
return py::cast<std::string>(casted);
108117
}
109118
#endif

0 commit comments

Comments
 (0)