| 23 | |
| 24 | template <typename T> |
| 25 | std::optional<T> get_if(py::dict d, const std::string &key) { |
| 26 | if (has_key(d, key)) { |
| 27 | try { |
| 28 | py::object obj = d[py::str(key)]; |
| 29 | return obj.cast<T>(); |
| 30 | } catch (const py::cast_error &) { |
| 31 | throw py::type_error("Key '" + key + "' is not of expected type."); |
| 32 | } |
| 33 | } |
| 34 | return std::nullopt; |
| 35 | } |
| 36 | |
| 37 | inline std::string to_lower(const std::string &s) { |
| 38 | std::string lower; |