diff --git a/setup.cfg b/setup.cfg index 212333f..cdfb5cf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = pytomlpp -version = 0.3.4 +version = 0.3.5 author = Bob Fang author_email = bob.fang.london@gmail.com license_file = LICENSE diff --git a/src/encoding_decoding.cpp b/src/encoding_decoding.cpp index 31d0125..5bdcf5a 100644 --- a/src/encoding_decoding.cpp +++ b/src/encoding_decoding.cpp @@ -95,12 +95,17 @@ toml::table py_dict_to_toml_table(const py::dict &object) { for (auto &&it : object) { auto key = it.first; auto value = it.second; + if (!py::isinstance(key)) throw py::type_error("key must be a string..."); std::string key_string = std::string(py::str(key)); bool insert_ok = true; - if (py::isinstance(value)) { + if (py::isinstance(value)) { + bool bool_value = value.cast(); + auto insert = t.insert_or_assign(key_string, bool_value); + insert_ok = insert.second; + } else if (py::isinstance(value)) { int64_t int_value = value.cast(); auto insert = t.insert_or_assign(key_string, int_value); insert_ok = insert.second; @@ -112,10 +117,6 @@ toml::table py_dict_to_toml_table(const py::dict &object) { std::string string_value = value.cast(); auto insert = t.insert_or_assign(key_string, string_value); insert_ok = insert.second; - } else if (py::isinstance(value)) { - bool bool_value = value.cast(); - auto insert = t.insert_or_assign(key_string, bool_value); - insert_ok = insert.second; } else if (py::isinstance(value)) { toml::table table_value = py_dict_to_toml_table(value.cast()); auto insert = t.insert_or_assign(key_string, std::move(table_value)); diff --git a/src/pytomlpp/__init__.py b/src/pytomlpp/__init__.py index 5ed679c..bec9fa2 100644 --- a/src/pytomlpp/__init__.py +++ b/src/pytomlpp/__init__.py @@ -5,5 +5,6 @@ from ._impl import DecodeError from ._impl import dumps from ._impl import loads +from ._impl import lib_version from ._io import dump from ._io import load