Commit 38111ef0 by Ralf W. Grosse-Kunstleve Committed by Copybara-Service

`Status` `.raw_code()` bug fix.

Fixes a bug introduced with https://github.com/pybind/pybind11_abseil/commit/01fd6b4fa611ee3cb67420fcb6e6fd6006215ee0

PiperOrigin-RevId: 443736276
parent 9aa816a0
......@@ -149,9 +149,7 @@ void RegisterStatusBindings(module m) {
.def("to_string", [](const absl::Status& s) { return s.ToString(); })
.def("__repr__", [](const absl::Status& s) { return s.ToString(); })
.def_static("OkStatus", DoNotThrowStatus(&absl::OkStatus))
.def("raw_code", [](const absl::Status& self) {
return static_cast<int>(self.code());
})
.def("raw_code", &absl::Status::raw_code)
.def("CanonicalCode", [](const absl::Status& self) {
return static_cast<int>(self.code());
})
......
......@@ -153,6 +153,12 @@ PYBIND11_MODULE(status_example, m) {
class_<IntGetter, PyIntGetter>(m, "IntGetter")
.def(init())
.def("Get", &IntGetter::Get);
// Needed to exercise raw_code() != code().
m.def("status_from_int_code", [](int code, const std::string& msg) {
return google::DoNotThrowStatus(
absl::Status(static_cast<absl::StatusCode>(code), msg));
});
}
} // namespace test
......
......@@ -136,6 +136,11 @@ class StatusTest(absltest.TestCase):
self.assertEqual(ok_status.error_message(), '')
self.assertIsNone(ok_status.IgnoreError())
def test_raw_code_ne_code(self):
st500 = status_example.status_from_int_code(500, 'Not a canonical code.')
self.assertEqual(st500.raw_code(), 500)
self.assertEqual(st500.code(), status.StatusCode.UNKNOWN)
class IntGetter(status_example.IntGetter):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment