Skip to content

Commit 2042664

Browse files
committed
fix #46
1 parent c2ace26 commit 2042664

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = pytomlpp
3-
version = 0.3.4
3+
version = 0.3.5
44
author = Bob Fang
55
author_email = [email protected]
66
license_file = LICENSE

src/encoding_decoding.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,17 @@ toml::table py_dict_to_toml_table(const py::dict &object) {
9595
for (auto &&it : object) {
9696
auto key = it.first;
9797
auto value = it.second;
98+
9899
if (!py::isinstance<py::str>(key))
99100
throw py::type_error("key must be a string...");
100101

101102
std::string key_string = std::string(py::str(key));
102103
bool insert_ok = true;
103-
if (py::isinstance<py::int_>(value)) {
104+
if (py::isinstance<py::bool_>(value)) {
105+
bool bool_value = value.cast<py::bool_>();
106+
auto insert = t.insert_or_assign(key_string, bool_value);
107+
insert_ok = insert.second;
108+
} else if (py::isinstance<py::int_>(value)) {
104109
int64_t int_value = value.cast<py::int_>();
105110
auto insert = t.insert_or_assign(key_string, int_value);
106111
insert_ok = insert.second;
@@ -112,10 +117,6 @@ toml::table py_dict_to_toml_table(const py::dict &object) {
112117
std::string string_value = value.cast<py::str>();
113118
auto insert = t.insert_or_assign(key_string, string_value);
114119
insert_ok = insert.second;
115-
} else if (py::isinstance<py::bool_>(value)) {
116-
bool bool_value = value.cast<py::bool_>();
117-
auto insert = t.insert_or_assign(key_string, bool_value);
118-
insert_ok = insert.second;
119120
} else if (py::isinstance<py::dict>(value)) {
120121
toml::table table_value = py_dict_to_toml_table(value.cast<py::dict>());
121122
auto insert = t.insert_or_assign(key_string, std::move(table_value));

src/pytomlpp/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
from ._impl import DecodeError
66
from ._impl import dumps
77
from ._impl import loads
8+
from ._impl import lib_version
89
from ._io import dump
910
from ._io import load

0 commit comments

Comments
 (0)