Skip to content

Commit

Permalink
fix #46
Browse files Browse the repository at this point in the history
  • Loading branch information
bobfang1992 committed Jan 11, 2021
1 parent c2ace26 commit 2042664
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = pytomlpp
version = 0.3.4
version = 0.3.5
author = Bob Fang
author_email = [email protected]
license_file = LICENSE
Expand Down
11 changes: 6 additions & 5 deletions src/encoding_decoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<py::str>(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<py::int_>(value)) {
if (py::isinstance<py::bool_>(value)) {
bool bool_value = value.cast<py::bool_>();
auto insert = t.insert_or_assign(key_string, bool_value);
insert_ok = insert.second;
} else if (py::isinstance<py::int_>(value)) {
int64_t int_value = value.cast<py::int_>();
auto insert = t.insert_or_assign(key_string, int_value);
insert_ok = insert.second;
Expand All @@ -112,10 +117,6 @@ toml::table py_dict_to_toml_table(const py::dict &object) {
std::string string_value = value.cast<py::str>();
auto insert = t.insert_or_assign(key_string, string_value);
insert_ok = insert.second;
} else if (py::isinstance<py::bool_>(value)) {
bool bool_value = value.cast<py::bool_>();
auto insert = t.insert_or_assign(key_string, bool_value);
insert_ok = insert.second;
} else if (py::isinstance<py::dict>(value)) {
toml::table table_value = py_dict_to_toml_table(value.cast<py::dict>());
auto insert = t.insert_or_assign(key_string, std::move(table_value));
Expand Down
1 change: 1 addition & 0 deletions src/pytomlpp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2042664

Please sign in to comment.