diff --git a/include/pybind11_json/pybind11_json.hpp b/include/pybind11_json/pybind11_json.hpp index d1a3744..19ae9dc 100644 --- a/include/pybind11_json/pybind11_json.hpp +++ b/include/pybind11_json/pybind11_json.hpp @@ -31,14 +31,14 @@ namespace pyjson { return py::bool_(j.get()); } - else if (j.is_number_integer()) - { - return py::int_(j.get()); - } else if (j.is_number_unsigned()) { return py::int_(j.get()); } + else if (j.is_number_integer()) + { + return py::int_(j.get()); + } else if (j.is_number_float()) { return py::float_(j.get()); diff --git a/test/test_pybind11_json.cpp b/test/test_pybind11_json.cpp index 9efda20..2d9cc82 100644 --- a/test/test_pybind11_json.cpp +++ b/test/test_pybind11_json.cpp @@ -315,6 +315,27 @@ TEST(nljson_serializers_fromjson, integer) ASSERT_EQ(obj2.cast(), 36); } +TEST(nljson_serializers_fromjson, integer_large_unsigned) +{ + // Note: if the asserts below error, the large number is printed as "-1" with + // an overflow error. This is only in the output step in pybind. Calling + // py::print on the objects shows the correct large unsigned integer. + + py::scoped_interpreter guard; + uint64_t original = 13625394757606569013ull; + py::int_ py_orig = original; + nl::json j = original; + py::object obj = j; + + ASSERT_TRUE(py::isinstance(obj)); + ASSERT_EQ(obj.cast(), original); + + py::int_ obj2 = j; + + // Use .equal to compare values not pointers + ASSERT_TRUE(obj2.equal(py_orig)); +} + TEST(nljson_serializers_fromjson, float_) { py::scoped_interpreter guard;