Replace error printing code gated by NDEBUG with a new flag: PYBIND11_DETAILED_ERROR_MESSAGES (#3913)

* Update cast.h

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Move definition to detail/common, change name, apply everywhere

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Rename debug_enabled in tests to detailed_error_messages_enabled
This commit is contained in:
Michael Voznesensky
2022-05-02 12:30:19 -07:00
committed by GitHub
parent 75007dda72
commit f0b9f755e4
10 changed files with 82 additions and 66 deletions

View File

@@ -216,15 +216,15 @@ def test_metaclass_override():
def test_no_mixed_overloads():
from pybind11_tests import debug_enabled
from pybind11_tests import detailed_error_messages_enabled
with pytest.raises(RuntimeError) as excinfo:
m.ExampleMandA.add_mixed_overloads1()
assert str(
excinfo.value
) == "overloading a method with both static and instance methods is not supported; " + (
"compile in debug mode for more details"
if not debug_enabled
"#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for more details"
if not detailed_error_messages_enabled
else "error while attempting to bind static method ExampleMandA.overload_mixed1"
"(arg0: float) -> str"
)
@@ -234,8 +234,8 @@ def test_no_mixed_overloads():
assert str(
excinfo.value
) == "overloading a method with both static and instance methods is not supported; " + (
"compile in debug mode for more details"
if not debug_enabled
"#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for more details"
if not detailed_error_messages_enabled
else "error while attempting to bind instance method ExampleMandA.overload_mixed2"
"(self: pybind11_tests.methods_and_attributes.ExampleMandA, arg0: int, arg1: int)"
" -> str"
@@ -344,16 +344,16 @@ def test_cyclic_gc():
def test_bad_arg_default(msg):
from pybind11_tests import debug_enabled
from pybind11_tests import detailed_error_messages_enabled
with pytest.raises(RuntimeError) as excinfo:
m.bad_arg_def_named()
assert msg(excinfo.value) == (
"arg(): could not convert default argument 'a: UnregisteredType' in function "
"'should_fail' into a Python object (type not registered yet?)"
if debug_enabled
if detailed_error_messages_enabled
else "arg(): could not convert default argument into a Python object (type not registered "
"yet?). Compile in debug mode for more information."
"yet?). #define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for more information."
)
with pytest.raises(RuntimeError) as excinfo:
@@ -361,9 +361,9 @@ def test_bad_arg_default(msg):
assert msg(excinfo.value) == (
"arg(): could not convert default argument 'UnregisteredType' in function "
"'should_fail' into a Python object (type not registered yet?)"
if debug_enabled
if detailed_error_messages_enabled
else "arg(): could not convert default argument into a Python object (type not registered "
"yet?). Compile in debug mode for more information."
"yet?). #define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for more information."
)