Commit f735c948 by Ralf W. Grosse-Kunstleve Committed by Copybara-Service

Change third_party/pybind11_abseil `StatusNotOk` to raise an exception when…

Change third_party/pybind11_abseil `StatusNotOk` to raise an exception when constructed with a plain `str`.

Step 2 of third_party/pybind11_abseil `StatusNotOk` convergence with the Google-internal type.

PiperOrigin-RevId: 473295335
parent 0c45d0f5
......@@ -173,13 +173,7 @@ void RegisterStatusBindings(module m) {
pybind11::exec(R"(
class StatusNotOk(Exception):
def __init__(self, *args):
if len(args) != 1 or isinstance(args[0], str):
# THIS WILL BECOME AN ERROR IN THE FUTURE.
self._status = None
Exception.__init__(self, *args)
return
status = args[0]
def __init__(self, status):
assert status is not None
assert not status.ok()
self._status = status
......@@ -187,19 +181,16 @@ void RegisterStatusBindings(module m) {
@property
def status(self):
assert self._status is not None
return self._status
@property
def code(self):
assert self._status is not None
# code is int by choice. Sorry it would be a major API break to make
# this an enum.
return self._status.raw_code()
@property
def message(self):
assert self._status is not None
return self._status.message()
)",
m.attr("__dict__"), m.attr("__dict__"));
......
......@@ -57,8 +57,9 @@ class StatusTest(absltest.TestCase):
self.assertEqual(e.message, 'Cnclld')
def test_status_nok_ok_str(self):
e = status.StatusNotOk('Deprecated.')
self.assertEqual(str(e), 'Deprecated.')
with self.assertRaises(AttributeError) as cm:
status.StatusNotOk('')
self.assertEqual(str(cm.exception), "'str' object has no attribute 'ok'")
def test_status_nok_ok_none(self):
with self.assertRaises(AssertionError) as cm:
......
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